Understanding the difference between const, readonly, and init is extremely important for mastering C# fundamentals and clearing .NET interviews.
🎥 Watch the full explanation video here: Const vs Readonly vs Init in C#
A const field is a compile-time constant. Its value must be known at compile time and must be assigned at declaration.
public const double PI = 3.14159;
If you change a const value in a library, all referencing assemblies must be recompiled.
A readonly field is a runtime constant. It can be assigned either at declaration or inside the constructor.
public class Student
{
public readonly DateTime AdmissionDate;
public Student()
{
AdmissionDate = DateTime.Now;
}
}
The init keyword (introduced in C# 9) allows properties to be set only during object initialization.
public class Employee
{
public string Name { get; init; }
}
var emp = new Employee { Name = "Sudipto" };
When using object initializer syntax:
var emp = new Employee { Name = "Sudipto" };
The constructor runs first, and then the property is assigned.
| Feature | const | readonly | init |
|---|---|---|---|
| Evaluated At | Compile Time | Runtime | Runtime |
| Works On | Fields | Fields | Properties |
| Assigned in Constructor | No | Yes | No |
| Immutable After Creation | Yes | Yes | Yes |
If you want strong fundamentals in C#, you must clearly understand when values are determined — compile time vs runtime — and how immutability works in .NET.
For deep .NET learning and 1-to-1 training, feel free to explore more resources.
🚀 Keep Learning. Stay Fundamental.
To keep every session productive and distraction-free, please follow these simple guidelines:
Following these guidelines helps you focus better and ensures I can deliver the best learning experience in every class.
I prefer to start with a short 10-minute free call so I can understand:
Why? Because course content, teaching pace, and fees all depend on your needs — there’s no “one-size-fits-all” pricing. Please leave your details below, and I’ll get back to you to arrange a convenient time for the call.
Note: Payment is made only after your first class, once you’re completely satisfied. However, fees paid after the first class are non-refundable. This helps maintain scheduling commitments and allows me to reserve your preferred time slot with full attention.