Variable & Data types - store and manipulate information(C#)

Patel Dhiren
2 min readMay 25, 2023

--

In C#, a variable is a named storage location that holds a value of a specific type.It allows you to store and manipulate data within your program. Data types define the kind of values that a variable can store and the operations that can be performed on those values. Each data type has a specific range of values it can hold and a set of operations that can be applied to those values.

In C#, there are several built-in data types, including:

  • Integer types (e.g., int, long, short) for storing whole numbers.
  • Floating-point types (e.g., float, double) for storing decimal numbers with varying levels of precision.
  • Character type (char) for storing individual characters.
  • String type (string) for storing sequences of characters.
  • Boolean type (bool) for storing true/false values.
  • And many more.

Each data type has its own characteristics, such as the range of values it can hold, the amount of memory it occupies, and the operations that can be performed on it.

Let’s continue with the example of a laptop to illustrate variable and datatype in C#:

class Program
{
static void Main()
{
string laptopBrand = "Dell vostro 5620P";
int laptopRAM = 16;
double laptopPrice = 75590.00;
char laptopCode = 'sbo-d562004win9';
bool isLaptopAvailable = true;

Console.WriteLine("Laptop brand: " + laptopBrand);
Console.WriteLine("Laptop RAM: " + laptopRAM + "GB");
Console.WriteLine("Laptop price: ₹" + laptopPrice);
Console.WriteLine("Laptop code: " + laptopCode);
Console.WriteLine("Is laptop available? " + isLaptopAvailable);
}
}

//OUTPUT
// Laptop brand: Dell vostro 5620P
// Laptop RAM: 16GB
// Laptop price: ₹75590.00
// Laptop code: sbo-d562004win9
// Is laptop available? True

In this example, we use different data types to store information about a laptop:

  • laptopBrand is a string variable that holds the brand name of the laptop ("Dell vostro 5620P" in this case).
  • laptopRAM is an integer variable that represents the amount of RAM in gigabytes (16 in this case).
  • laptopPrice is a double variable that represents the price of the laptop (₹75590.00 in this case).
  • laptopCode is a character variable that represents a unique code for the laptop model ('sbo-d562004win9' in this case).
  • isLaptopAvailable is a boolean variable indicating whether the laptop is available (true in this case).

Thank you! I’m glad to hear that you’re enjoying the learning process. If you have any more questions or need further assistance, feel free to ask. Happy learning to you too!

--

--