Class and Object in C# in Hindi – क्लास और ऑब्जेक्ट क्या है? – .NET

Hello दोस्तों! आज हम इस पोस्ट में Class and Object in C# in Hindi (C-sharp में क्लास और ऑब्जेक्ट क्या है?) के बारें में पढेंगे. और इनके examples को भी देखेंगे. इसे आप पूरा पढ़िए, यह आपको आसानी से समझ में आ जायेगा. तो चलिए start करते हैं:-

Class and Object in C# in Hindi

C# एक object-oriented प्रोग्रामिंग है. C# में सब कुछ class और object के साथ जुडा हुआ रहता है. एक Class यूजर के द्वारा define किया हुआ एक prototype होता है जिसमें से objects को create किया जाता है. इसमें program को objects और class का प्रयोग करके design किया जाता है.

Class in C# in Hindi – क्लास क्या है?

  • C# में, Class एक blueprint होता है जिसमें से objects को create किया जाता है.

  •  Class समान प्रकार के objects का एक group (समूह) होता है.

  • एक क्लास के पास methods, fields और constructors आदि होते हैं.

  • एक क्लास properties और methods का encapsulation होता है जिसका प्रयोग real time entity को प्रस्तुत करने के लिए किया जाता है.

  • Class को create करने के लिए class keyword का प्रयोग किया जाता है.

  • C# में, क्लास polymorphism और inheritance को भी support करती है और ये derived class और base class के कांसेप्ट को भी प्रदान करती है.

C# में Class को create करना

C# में एक क्लास को class कीवर्ड के द्वारा create या declare किया जाता है और इसके बाद इसमें class का name होता है. इसका syntax निम्नलिखित है:-

class Student 
{
string name = "Yugal";
}

इसमें हमने Student नाम की class को create किया है और इसमें name एक variable है.

Object in C# in Hindi – ऑब्जेक्ट क्या है?

  • C# में, Object एक real time entity होता है. उदाहरण के लिए – pen, chair, laptop, mobile, car आदि.

  • object एक entity है जिसके पास behavior और state होता है. इसमें state का मतलब है data और behavior का मतलब है functionality.

  • यह एक runtime entity है क्योंकि इसे run-time में create किया जाता है.

  • ऑब्जेक्ट class का एक instance (उदाहरण) होता है. class के सभी members को object के द्वारा access किया जा सकता है.

Object को create करना

object को एक class में से create किया जाता है. हमने ऊपर Student नाम की class को पहले से ही create किया हुआ है. अब हम इस class से object को create करेंगे.

Student के object को create करने के लिए, object name के साथ class name को specify किया जाता है. और new keyword का प्रयोग किया जाता है. इसका example नीचे दिया गया है:-

class Student 
{
string name = "Yugal";

static void Main(string[] args)
  {
 Student myObj = new Student();
 Console.WriteLine(myObj.color);
  }
}

C# Class और Object का Example

नीचे आपको C# में object और class का program दिया गया है:-

using System;  
public class Student  
{  
int id;
String name; 
         
public static void Main(string[] args)  
{  
// creating an object of Student    

Student s1 = new Student();
s1.id = 150;  
s1.name = "Yugal Joshi";  
Console.WriteLine(s1.id);  
Console.WriteLine(s1.name);  
  
}  
}  

इसका आउटपुट

150
Yugal Joshi

References:- https://www.geeksforgeeks.org/c-sharp-class-and-object/

c# class and object in Hindi - .net

निवेदन:- अगर आपके लिए यह आर्टिकल उपयोगी रहा हो तो इसे अपने friends और classmates के साथ अवश्य share कीजिये. और आपके .net programming से सम्बन्धित कोई सवाल हो तो उसे नीचे comment करके बताइए.

मैं आपके लिए नए-नए नोट्स लाते रहता हूँ. इसलिए आपका कोई suggestion हो तो उसे भी आप बता सकते हैं. जिससे कि वेबसाइट को और भी बेहतर बनाया जा सके.

Leave a Comment