How to Declaration and assign of variable in C#
Variable
- int: Represents whole numbers (e.g., 42).
- float: Represents single-precision floating-point numbers (e.g., 3.14f).
- double: Represents double-precision floating-point numbers (e.g., 3.14).
- decimal: Represents decimal numbers with higher precision (e.g., 3.14m).
- byte: Represents unsigned integers (0 to 255).
- short: Represents small integers (-32,768 to 32,767).
- long: Represents large integers (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807).
- char: Represents a single character (e.g., 'A', '5', '$').
- bool: Represents a Boolean value (either true or false).
- string: Represents a sequence of characters (e.g., "Hello, World!").
- enum: Represents a set of named values (e.g., days of the week, months).
- type[]: Represents a collection of elements of a specific type (e.g., int[], string[]).
- object: Represents any type of data (a reference to an instance of a class).
Create Variables
float temperature; // declaring a float variable named "temperature"
bool isStudent; // declaring a boolean variable named "isStudent"
string name; // declaring a string variable named "name"
float pi = 3.14f; // declaring and initializing a float variable named "pi" with a value of 3.14
bool isActive = true; // declaring and initializing a boolean variable named "isActive" with a value of true
string message = "Hello, world!"; // declaring and initializing a string variable named "message" with a value of "Hello, world!"
- It must start with a letter or underscore (_).
- It can contain letters, digits, and underscores.
- It cannot contain spaces or special characters (except underscores).
class Program
{
static void Main(string[] args)
string Name = "Amit Kumar";
Console.WriteLine("All information are :");
Console.WriteLine(Age);
Console.WriteLine(num1);
Console.WriteLine(num2);
Console.WriteLine(ch);
Console.ReadLine();
}
}
}













