Classes and Objects
A class defines a reusable reference type; each object has its own state.
How it works
Model state and behavior together in a C# class.
The constructor establishes valid initial state and the method changes state through a controlled operation.
Runnable C# example
Program.cs
using System;
class Counter
{
public int Value { get; private set; }
public void Increment() => Value++;
}
class Program
{
static void Main()
{
var counter = new Counter();
counter.Increment();
counter.Increment();
Console.WriteLine(counter.Value);
}
}
2Practice with the debugger
Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.