.Net C# @ variables

An uncommon trick, if you really want to declare a variable with the same name as a reserved keyword you can use the @ prefix to do so.

using System;

namespace CsharpAtVariablesDemo
{
    class CsharpAtVariablesExample
    {
        static void Main()
        {
            var @int = 10000;

            Console.WriteLine(@int);
            
            Console.ReadKey();
        }
    }
}

Returns:

10000

.Net C# the volatile keyword

Quick demo of the volatile keyword. Volatile indicates a field might be modified by multiple threads that are executing concurrently. More at volatile (C# Reference).

using System;
using System.Threading;

namespace CsharpVolatileDemo
{
    class CsharpVolatileExample
    {
        private static volatile int _volatileValue;

        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        static void Main()
        {

            var thread = new Thread(Volatile);
            
            thread.Start();
            
            Thread.Sleep(1000);
            
            Console.WriteLine("Value: {0}", _volatileValue);
            
            thread.Abort();
        }

        /// <summary>
        /// Volatile static method.
        /// </summary>
        private static void Volatile()
        {
            while (true)
            {
                _volatileValue++;
            }
        }
    }
}