Member-only story

C# Blog Series 2: Understanding Data Types in C#

Ninad K
3 min read3 days ago

Introduction

In C#, every variable must have a defined data type, which determines what kind of values it can store. Understanding data types is fundamental to writing efficient and error-free C# programs. In this guide, we’ll explore different C# data types with interactive examples.

Commonly Used Data Types in C#

C# provides a variety of data types to store different kinds of values:

Declaring and Initializing Variables in C#

Code Example: Storing Different Types of Data

using System;
class DataTypesExample
{
static void Main()
{
string userName = "Alice"; // A string variable
int userAge = 25; // An integer variable
double userHeight = 5.7; // A double variable
bool isStudent = true; // A boolean variable
char grade = 'A'; // A character variable
Console.WriteLine($"User Info: Name = {userName}, Age = {userAge}, Height = {userHeight}ft, Student = {isStudent}, Grade = {grade}");
}
}

--

--

No responses yet