<aside> Understanding data types is fundamental to C# programming. This guide covers all essential data types and their practical applications.

</aside>

🔢 Numeric Types

Decimal Numbers

When using decimal numbers in C#, always use dots (.) rather than commas (,) as decimal separators.

Floating-Point Types:

Integer Types:

Type Size Range Usage
sbyte 8-bit -128 to 127 Very small numbers
short 16-bit -32,768 to 32,767 Small numbers
int 32-bit -2^31 to 2^31-1 Most common choice
long 64-bit -2^63 to 2^63-1 Very large numbers

📝 Text Types

Character (char)

char letter = 'A';    // Single character
char symbol = '$';    // Special character
char digit = '7';     // Numeric character

String

string name = "John";              // Basic string
string path = @"C:\\Program Files"; // Verbatim string
string interpolated = $"Hello {name}"; // String interpolation

String Operations

string text = "Hello World";
int length = text.Length;           // Get length
string upper = text.ToUpper();      // Convert to uppercase
string lower = text.ToLower();      // Convert to lowercase
string sub = text.Substring(0, 5);  // Get "Hello"
bool contains = text.Contains("World");  // Check content
string[] words = text.Split(' ');   // Split into array

⚖️ Boolean (bool)

Represents true/false values, essential for control flow and decision-making.

bool isValid = true;
bool hasError = false;

// Common boolean operations
bool andResult = isValid && hasError;  // AND
bool orResult = isValid || hasError;   // OR
bool notResult = !isValid;             // NOT