Classes & Objects
Classes Are Blueprints
A class is like a blueprint for a house. The blueprint itself isn't a house β it's a plan that describes what a house looks like (rooms, doors, windows). When you actually build a house from that blueprint, that's an object (also called an "instance").
You can build many houses from the same blueprint. Each house is its own thing β paint one red, another blue β but they all share the same structure.
Classes are the building blocks of every data structure, from linked lists to trees. A class bundles together:
- Fields/Properties β the data (what the object knows)
- Methods β the behavior (what the object can do)
- Constructor β the setup instructions (how to build it)
Your First Class
Properties β Smart Fields
Properties look like fields but have superpowers. The { get; set; } syntax creates an auto-property β C# generates a hidden backing field automatically. But you can also write custom logic:
getβ runs when someone reads the valuesetβ runs when someone assigns a value (usevaluekeyword)initβ like set, but only works during object creation
Properties let you add validation β like a bouncer checking IDs at the door.
Properties & Access Modifiers
Static Members β Shared Across All Objects
Normal properties and methods belong to each individual object. static members belong to the class itself β they're shared by everyone.
Think of it this way: Every student has their own name (instance property), but they all share the same school name (static property). You access static members through the class name, not through an object.