Class is a blueprint for creating an object, and is an actual instance created from a class. A class can hold fields/properties and methods.Object
csharp
class Car
{
public string Color = "red";
public void Drive()
{
Console.WriteLine("The car is driving.");
}
}
class Program
{
static void Main(string[] args)
{
Car myCar = new Car();
Console.WriteLine(myCar.Color);
myCar.Drive();
}
}What this code does
Carclass is the blueprint for a car object.Colorfield stores the object's data.Drive()method shows the object's behavior.new Car()creates a new Car object.
You should see
red The car is driving.