C# Variables

Declaring Variables

All variables in C# must be declared with a type:

int age;
string name;
bool isOnline;

Initializing Variables

You can assign values during declaration or after:

int age = 25;
string name;
name = "Alice";

Variable Naming Rules

  • Must start with a letter or underscore
  • Cannot use C# keywords
  • Case-sensitive (e.g. total ≠ Total)

Multiple Declarations

Loading...
Output:

Constants

Use const to declare values that never change:

Loading...
Output:

Practice Prompt

What does this print?

Loading...
Output:

Need Help?

Ask the AI if you need help understanding or want to dive deeper in any topic