Variables - Assigning value in C#


You can assign a value to a variable statically like this:


using System;

namespace forgetCode
{
    class Program
    {
        static void Main(string[] args)
        {

            string name = "Forget code";
            Console.WriteLine(name);

        }      
    }
}


Output:
Forget code



You can assign a value to a variable dynamically like this:


using System;

namespace forgetCode
{
    class Program
    {
        static void Main(string[] args)
        {

            string name;
            Console.WriteLine("Enter your name here");
            name = Console.ReadLine();
            Console.WriteLine("Your name : "+name);

        }      
    }
}

Output:
Enter your name here
Forget Code
Your name : Forget Code

..