C# constants in hindi-c# कोन्स्तंट्स क्या होता है ?

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

C# constants का परिचय

ऐसी values या variables जो प्रोग्राम में change नहीं किये जा सकते है constants कहलाते है constants compile time पर compiler के द्वारा आप known होते है ये programmer के द्वारा डिफाइन किये जाते है और प्रोग्राम की पूरी life में change नहीं होते है

constants के variables को normal variables से अलग होते है normal variables की values को runtime पर किसी भी ऑपरेशन के द्वारा change किया जा सकता है लेकिन constants variables की values को run time में किसी भी प्रकार से change नहीं किया जा सकता है

सभी popular programming languages की तरह c# आपको constants को डिफाइन करने की ability को provide करती है c# में constants दो प्रकार के होते है

constants literals

ऐसी values जिन्हें आप प्रोग्राम में directly प्रयोग करते है constant literals कहलाती है example के लिए आपको निचे दिया गए code को देखिये

b=a*2;

उपर दिए गए code में 2 एक literal है इसे प्रोग्राम में directly प्रयोग किया गया है प्रोग्राम के run होने के दोरान इसे change नहीं किया जा सकता है

constant literals का उपयोग programmers के द्वारा आवशाक्तानुसार किया जाता है यदि आपने प्रोग्राम में बहुत अधिक constant literals का प्रयोग किया है और बाद में आपको उन्हें change करने की आवश्यकता पड़ती है तो आपको manually हर literals को ढूढ़ कर change करना होता है

constant literals के इसी drawback के कारण इन्हे बहुत अधिक प्रयोग करने की सलाह नहीं दी जाती हा इसके बजाय आपको constant variables का उपयोग करना चाहिए

constants variables

जैसा की आपको पता है की constant variable में ऐसे variables होते है जिनकी values change नहीं की जा सकती है इन्हे प्रोग्राम में किसी normal(const) के साथ डिफाइन किया जाता है

constant literals की अपेक्षा इन्हे प्रयोग करना बेहतर होता है क्योकि यदि आपको प्रोग्राम में बहुत अधिक constant variables का प्रयोग किया है तो भी आप इन्हे एक ही जगह पर change करते है और वह वैल्यू को automatically पुरे प्रोग्राम में update हो जाती है constant literals की तरह आपको इन्हे manually ढूढ़ कर change करने की आवश्कता नहीं होती है

c# में केवल built in types ही constant को डिफाइन किये जा सकते है classes ,structs और arrays को constant नहीं declare किया जा सकता है इसके आलावा c# में methods ,प्रॉपर्टीज और events को भी constants को नहीं डिफाइन किया जा सकता है

syntax of c# constants

constants literals को आप directly डिफाइन करते है की इन्हे डिफाइन करने के लिए किसी प्रकार के special syntax की आवश्यकता नहीं होती है

constant variable को डिफाइन करने का general syntax आपको निचे दिया जा रहा है

access-modifier const-modifier data-type variable-name=value;

जैसा की आप उपर दी गए syntax में देख सकते है की constant variables को डिफाइन करने के लिए सबसे पहले आप access modifier को डिफाइन करते है const modifier के द्वारा ही compiler को पता चलता है की आप एक constant variable को डिफाइन कर सकते है

 

const modifier के बाद data type और variables का नाम को declare किया जाता है इसके बाद variables को initialize किया जाता है constant variables को declare करने के साथ compile time पर initialize किया जाना अनिवार्य होता है

example of c# constants

उपर दिए गए example में आपको निचे दिए गए आउटपुट generate होता है

Using system;
Class myClass
{
   Static void Main()
    {
          Const int Num=2;
            Console.WriteLine(“Num is {0}”,Num);
      }
}

उपर दिए गए example में आपको निचे दिया गया इसका आउटपुट generate होता है

Num is : 2

 

c# constants in hindi

reference-https://www.tutorialspoint.com/csharp/csharp_constants.htm

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

Leave a Comment