C# events in hindi-C# इवेंट्स क्या है?

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

introduction to c# events

  • c# में events को एक ऐसा feature होता है जिसके द्वारा एक class किसी दूसरी class को कोई खास event(घटना) को generate होने पर notification को भेज सकते है दूसरी class के notification को प्राप्त करके generate होने वाली event को (handle method के द्वारा ) handle करती है
  • example के लिए windows को form या web application में यूजर के द्वारा किसी button को क्लिक करने पर button class event generate करती है और दूसरी class को notification भेजती है जिसमे उस event के लिए handler method को डिफाइन किया गया है
  • notification पाकर दूसरी class को handler method को execute करती है handler method में कोई भी action लिया जा सकता है जैसे की कोई message को show किया जा सकता है या कोई process को initiate (शुरू) की जा सकती है
  • जिस class में event को generate होता है वह publisher या event source class कहलाती है जो class उस event के लिए register या subscribe करती है वह सब्सक्राइबर या event destination class कहलाती है
  • यह आवश्यक नहीं है की event generate करने वाली class और event handle करने वाली class अलग अलग हो आप एक ही class से event को generate भी कर सकते है और उसे handle भी कर सकते है
  • मुख्यत: events किसी भी graphical user interface (window forms और web applications) में यूजर के द्वारा button क्लिक ,menu selection आदि में actions  के लिए generate होते है console application में event का अधिक प्रयोग नहीं होता है
  • एक c# में windows forms या web applications में button,selection menu,list boxes आदि में control के द्वारा generate होने वाले events के लिए आपको subscribe करना होता है इसके लिए आप (उसी class में या किसी दूसरी class में ) एक handler function को डिफाइन करते है और जो event को handler करेगा और उसे delegate के द्वारा event से associate करते है
  • कोई भी control कौन कौन से event को generate करता है यह visual studio express में आसानी से देखा जा सकता है इनमे से आप उस event को सेलेक्ट कर सकते है जिसे आप handle करना चाहते है
  • जैसे ही आप किसी event को सेलेक्ट करते है तो IDE automatically एक event handler method और event के लिए subscribe करने वाला code add कर देते है आपको सिर्फ event को handler method में event को handle करने के लिए code लिखने की आवश्यकता होता है
  • किसी भी event के लिए एक से अधिक subscriber हो सकते है यानी की किसी event को handle करने के लिए एक से अधिक handler methods को डिफाइन किये जा सकते है जब ऐसा होता है तो event generate होने  पर सभी methods एक साथ call किये जाते है

handling c# events

c# में events को 3 steps में handle किया जा ता है

  • declaring delegate
  • declaring event with delegate name
  • declaring handler method

इन steps को निचे details से आपको दिया जा रहा है

declaring event delegate

किसी class के अन्दर आप event को डिक्लेअर करने से पहले उसके लिए delegate को define करना आवश्यक होता है यह delegate उस handler method से associated रहता है जो event को generate होने पर call होता है

इसके आलावा इस delegate को event declare करने के लिए भी प्रयोग किया जाता है इसलिए इस delegate को event delegate भी कहते है इसके बारे में आपको आगे सेक्शन में दिया जायेगा

handler method का signature (return type और parameters का type और सख्या)और delegate का signature identical (समान) होना चाहिए यहाँ पर delegate को method से associate करना नही बताया जा रहा है

c# delegate के बारे में विस्तृत से आपको जानकारी के लिए कृपया c# delegates in hindi tutorial में हो

declaring event

c# में events को declare करने का generate syntax आपको निचे दिया जा रहा है

जैसा की आप उपर दिए गए syntax में आप देख सकते है की c# में event को declare करने के लिए event keyword का प्रयोग किया जाता है इसके बाद उस delegate का नाम लिखा जाता है जो event generate होने पर invoke होगा इसके बाद event का नाम डिफाइन किया गया है

declaring handler method

handler method वह method होता है जो delegate के द्वारा invoke किया जाता है इसे delegate के साथ associate किया जाता है handler method में वह code लिखा जाता है जो event को generate होने पर execute होगा इसके बारे में आपको विस्तृत जानकारी के लिए आप c# delegate in hindi में नीच दिया है

example of c# events

c# में events को handle करना निचे आपको द्वारा समझाया जा रह है

using System
public delegate string eveDel(); //declaring event delegate
class eventDemo //subscriber class
{
    public string eventHandler()
    {
           return “event generated and handler succefully”;
      }
}
class eventDemoFinal  //publisher class
{
    static event eveDel bestEvent; //declaring event
    static void Main(string[] args)
     {
        string msg;
         eventDemo iD=new eventDemo();
         eveDel eDel=new eveDel
(eD.eventHandler);  //associating delegate & handler method
         eventDemo\final.bestEvent(); //generating event
          Console.WriteLine(msg);
     }
}

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

event generated and handler successfully

 

c# events in hindi

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

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

Leave a Comment