Lesson 2 of 15
Variables & Types
Variables and Types
C# is statically typed — every variable has a type declared at compile time:
int age = 25; // integer (whole number)
double gpa = 3.95; // floating-point number
string name = "Alice"; // text
bool isStudent = true; // true or false
You can also use var to let the compiler infer the type:
var x = 42; // compiler infers int
var pi = 3.14159; // compiler infers double
Type Conversion
Convert between types with casting or conversion methods:
int x = 7;
double d = (double)x; // cast int to double
string s = x.ToString(); // int to string
int n = int.Parse("42"); // string to int
Your Task
Declare these variables and print each on its own line:
intnamedagewith value30stringnamednamewith value"Bob"boolnamedactivewith valuetruedoublenamedscorewith value9.5
WasmSharp (.NET) loading...
Loading...
Click "Run" to execute your code.