How to declare variables in C#?

CsharpProgrammingServer Side Programming

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 −


 Live Demo

using System;
using System.Collections;

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


Integer variable:50
Published on 06-Aug-2018 15:49:42