Thursday, February 12, 2026

Static vs Non-Static Class Members in C#

 Static Members :Belong to the class, not to an object.
                            Only one copy exists.
                             Accessed using ClassName.
                            MemberNameMemory allocated only once.
public class Employee
{
    public static string CompanyName = "ABC Ltd";
}
Non-Static Members.
                            Belong to the object (instance).
                            Each object has its own copy.
                            Must create object to access.
public class Employee
{
    public string Name;
}

"Static members belong to the class and are shared by all objects. Non-static members belong to the object and require object creation to access."