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.