Classes क्या हैं
एक class एक blueprint है, जैसे किसी घर का plan या किसी toy का design। यह describe करता है कि उस type की चीज़ें क्या जानती हैं और क्या कर सकती हैं।
In this page:
Syntax
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
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();
}
}
Login to try C/C++/Java/PHP code in the editor
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. #}
आम गलतियां
- किसी class (blueprint) को किसी object (एक instance) के साथ confuse करना।
- members को
publicचिह्नित करना भूल जाना और फिर दूसरी classes से उन तक न पहुंच पाना, क्योंकि members default रूप से private हैं। - एक class में बहुत सारी असंबंधित responsibilities डालना।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: