How to assign values to variables in C#?


A variable is a name given to a storage area that our programs can manipulate. Each variable in C# has a specific type, which determines the size and layout of the variable's memory the range of values that can be stored within that memory and the set of operations that can be applied to the variable.

To assign values to a variable, add the value after the equal operator −

int a = 10;

Let us see how to assign values to a variable and print it

Example

 Live Demo

using System;

namespace Demo {

   class Program {

      static void Main(string[] args) {

         int a;

         a = 100;

         Console.WriteLine("a = {0}", a);
         Console.ReadLine();
      }
   }
}

Output

a = 100

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 20-Jun-2020

479 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements