C# enumeration in hindi-c# एनुमेरतिओन क्या है?

हेल्लो दोस्तों आज के इस पोस्ट में मैं आपको c# enumeration in hindi के बारे में आपको बताया जा रहा है की क्या होता है कैसे काम करता है तो चलिए शुरू करते है

C# enumeration type का परिचय

C# में enumeration के type एक ऐसे type है जिसके द्वारा आप named constants का सेट को डिफाइन कर सकते है किसी भी दुसरे type की तरह enumeration type के भी variables को क्रिएट किये जा सकते है इसके आलावा इन्हे ही directly भी प्रयोग किया जा सकता है

जैसा की आपको पता है की constants को fixed होते है और उनकी वैल्यू को भी प्रोग्राम में कही भी change नहीं होती है इसलिए ऐसी कोई भी सिचुएशन जहा पर variables की values पहले से known हो (या fixed) हो तो उसे condition में आप enumeration type को प्रयोग कर सकते है

enumeration type के द्वारा आप वैल्यू के रूप में limited named constants को प्रयोग करने के लिय बाध्य किया जाता है यानी की यदि आप enumeration के type का कोई व्ही variables को क्रिएट करते है तो उसके वाही values को assign की जाती है जो आपने enumeration type को declare करते समय ही डिफाइन की थी

example के लिए आप gender नाम का एक variables को क्रिएट करना चाहते है तो किसी भी person की gender इनफार्मेशन को स्टोर करता है जैसा की आप अनुमान लगा सकते है की इस variables की male और female दो ही possible values हो सकती है

इस सिचुएशन में enumeration type को क्रिएट करके आप यूजर को male या female में से कोई एक वैल्यू को enter करने के लिए bound कर सकते है यदि आप ऐसा नहीं किया जय तो यूजर कोई irrelevant वैल्यू भी enter कर सकते है

यदि बुनियादी तौर पर देखा जाए तो enumeration type के सभी constants को sequence में index numbers को assign होते है जैसा की किसी array में होता है जैसा की पहले constant का index number 0 होता है तो दुसरे constant का index number 1 होता है और इसी प्रकार से हर अगले constant के लिय यह index number को increase होता जाता है

enumeration type के लिए constants enumerators कहलाते है enumerators को किसी भी array की तरह लूप लगाकर traverse भी किया जा सकता है

एक बात को आपको हमेशा ध्यान में रखना चाहिए की enumeration type का scope हमेशा global रहता है इसे आप फंक्शन level पर नही डिफाइन कर सकते है ऐसा करने पर errors को generate होती है enumeration type को हमेशा namespace में या class से पहले डिफाइन करना ही बेहतर होता है

syntax of c# enumeration type

c# में enumeration type का general syntax आपको निचे दिया जा रहा है

enum-keyword enum-type-name{constant1,constant2,constant3 ………constantN};

जैसा की आप उपर दी गए syntax में आप देख सकते है की enumeration type को डिफाइन करने के लिए enum keyword का प्रयोग किया जाता है इस keyword के बाद enumeration type के नाम को डिफाइन किया जाता है नाम के बाद curly brackets में comma से separate करके constants(enumerators) की लिस्ट को डिफाइन की जाती है

enumerators(named constants) को values में भी assign की जा सकती है इसके लिए assignment operator को लगाकर आप values को डिफाइन करते है तो इसका syntax आपको निचे दिया जा रहा है

enum-keyword enum-type-name
{
    constant1 =value;
    constant2=value;
    ......
    ......
    constantN=value;
}

इस सिचुएशन में जब भी किसी enumerator(named constant) को एक्सेस किया जाता है तो उसकी वैल्यू को एक्सेस होती है

example of c# enumeration type

C# में enumeration type को simple example के द्वारा निचे दिया जा रहा है

using System;
enum Gender{Male,Femle}
class person
{
    Public static void  Main(String[] args)
     {
           Gender gender=Gender.Male;
            Console.WriteLine(“gender of this person is {0}”,gender);
     }
}

उपर दिए गए example में आपको निचे दिया जा रहा है

gender of this person is male

 

c# enumeration in hindi

reference-https://www.tutorialsteacher.com/csharp/csharp-enum

निवेदन:-आप सभी छात्र –छात्रों से निवेदन है की अगर आपको ये Topic(c# enumeration in hindii) या post अच्छा लगा हो तो कृपया आप इस वेबसाइट के बारे में अपने दोस्तों को जरुर बताये और -अगर कोई topic(c# enumeration in hindi) से संबधित प्रश्न हो तो कमेंट्स(comments) आपके लिए ही बना है और किसी Subject के लेकर भी कोई प्रश्न हो तो कमेंट करे

Leave a Comment