← Back to C# Course | Chapter 6: OOP Basics | Lesson 1 of 7

Classes

In this page:

  1. Classes

Classes

A class is a blueprint that bundles data (fields) and behavior (methods) into a single type. You define it once and create as many independent objects from it as you need. Classes are the foundation of object-oriented programming in C#.

Note: Class names conventionally use PascalCase, like BankAccount.

Example: Classes

markup
using System;

class Dog
{
    public string Name;
    public int Age;

    public void Bark()
    {
        Console.WriteLine($"{Name} says Woof!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        Dog d = new Dog();
        d.Name = "Rex";
        d.Age = 3;
        d.Bark();
    }
}
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.