0% found this document useful (0 votes)
10 views1 page

Variables (Different Types)

Uploaded by

wwx18194
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Variables (Different Types)

Uploaded by

wwx18194
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

Variables (Different Types)


Definition: Variables store data values, and in C#, you must declare them with a
specific data type. The data type determines what kind of values the variable can
hold.

Common Variable Types:

int: Stores whole numbers (e.g., 1, -5, 10)


double or float: Stores decimal numbers (e.g., 3.14, -0.001)
string: Stores text (e.g., "Hello", "123")
char: Stores a single character (e.g., 'a', '1')
bool: Stores true or false (e.g., true, false)

int age = 25; // Integer variable


double price = 19.99; // Decimal variable
string name = "John"; // String variable
char grade = 'A'; // Character variable
bool isStudent = true; // Boolean variable

When to use:

Use int when working with whole numbers (count, index, etc.).
Use double or float for fractional numbers (prices, measurements).
Use string for text data.
Use bool for true/false values.

You might also like