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

Classes क्या हैं

एक class एक blueprint है, जैसे किसी घर का plan या किसी toy का design। यह describe करता है कि उस type की चीज़ें क्या जानती हैं और क्या कर सकती हैं।

In this page:

  1. Classes
Syntax
csharp
class ClassName
{
    public type Field;

    public void MethodName()
    {
        // uses Field
    }
}

Classes

एक class एक blueprint है जो data (fields) और behavior (methods) को एक single type में बांधता है। आप इसे एक बार define करते हैं और इससे जितनी चाहें उतनी स्वतंत्र objects बनाते हैं। Classes C# में object-oriented programming की नींव हैं।

Note: Class names conventionally PascalCase उपयोग करते हैं, जैसे BankAccount।

उदाहरण: 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();
    }
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. किसी class (blueprint) को किसी object (एक instance) के साथ confuse करना।
  2. members को public चिह्नित करना भूल जाना और फिर दूसरी classes से उन तक न पहुंच पाना, क्योंकि members default रूप से private हैं।
  3. एक class में बहुत सारी असंबंधित responsibilities डालना।
🔒

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.