How to declare variables in C#?


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 declare variables −

<data_type> <variable_list>;

Let us see an example to declare two integer variables −

int a, b;

Above the variable is of int type. Let us declare a variable for other types −

Variable of float type.

float f;

Variable of double type.

double d;

Let us display a variable −

Example

 Live Demo

using System;
using System.Collections;

class Demo {
   static void Main() {
      int x = 50;
      Console.WriteLine("Integer variable:"+x);
   }
}

Output

Integer variable:50

Updated on: 20-Jun-2020

219 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements