Types, Variables, and Constants
C# checks types at compile time while var asks the compiler to infer a type from the assigned value.
How it works
Declare strongly typed values and constants in C#.
const creates a compile-time constant. var remains statically typed; price is still a decimal and cannot later hold unrelated data.
Runnable C# example
Program.cs
using System;
class Program
{
static void Main()
{
const decimal TaxRate = 0.10m;
var price = 25.00m;
int quantity = 4;
decimal total = price * quantity * (1 + TaxRate);
Console.WriteLine($"Total: {total:C}");
}
}
Total: ¤110.00Practice with the debugger
Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.