Roadmap › OOP Concepts in C# › Module: Classes and Objects
Lessons in this course (15)
4. Static members, static classes and partial classes
BasicMediumLesson 4 of 15
csharp
public static class MathHelper // cannot be instantiated or inherited
{
public static double Square(double x) => x * x;
}
public class Counter
{
public static int Instances; // shared across all objects
public Counter() => Instances++;
}
public partial class Customer { public string Name { get; set; } = ""; } // file 1
public partial class Customer { public string Display() => Name.ToUpper(); } // file 2 (e.g. generated code)Static members belong to the type, not to an object. Avoid mutable static state in web apps — it is shared by every request and thread.