MYSTERY ZILLION တွင် English သို့မဟုတ် Unicode ဖြင့်သာ အသုံးပြုခွင့်ရှိသည်။ ဇော်ဂျီ ၊ ဧရာ စသည်တို့ကို အသုံးပြုခွင့် မရှိ။ Unicode fonts များမှာ Mon3,Yunghkio, Myanamr3 စသည်များ အသုံးပြုနိုင်သည်။ Unicode Guide ကို ဒီမှာ Download ချပါ။ Zawgyi to Unicode Converter
Don't share ebook or software if nobody request. You can find free book websites on here. We are welcome for discussion or asking question instead.

Delegates and events in C#.Net

edited August 2014 in C#

how to use delegates and events in C#? Although I have read on the Internet and made tutorials. I can't understand. So please tell and point me good examples as possible as with Myanmar Language. Thank you.

Tagged:

မှတ်ချက်များ

  • Administrators

    http://www.tutorialspoint.com/csharp/csharp_delegates.htm

    tutorial လေးကို ဖတ်လိုက်ရင် နားလည်လွယ်ပါတယ်။

    using System;
    using System.IO;
    
    namespace DelegateAppl
    {
       class PrintString
       {
          static FileStream fs;
          static StreamWriter sw;
          // delegate declaration
          public delegate void printString(string s);
    
          // this method prints to the console
          public static void WriteToScreen(string str)
          {
             Console.WriteLine("The String is: {0}", str);
          }
          //this method prints to a file
          public static void WriteToFile(string s)
          {
             fs = new FileStream("c:\\message.txt",
             FileMode.Append, FileAccess.Write);
             sw = new StreamWriter(fs);
             sw.WriteLine(s);
             sw.Flush();
             sw.Close();
             fs.Close();
          }
          // this method takes the delegate as parameter and uses it to
          // call the methods as required
          public static void sendString(printString ps)
          {
             ps("Hello World");
          }
          static void Main(string[] args)
          {
             printString ps1 = new printString(WriteToScreen);
             printString ps2 = new printString(WriteToFile);
             sendString(ps1);
             sendString(ps2);
             Console.ReadKey();
          }
       }
    }
    

    အဲဒီ code လေးကို ကြည့်လိုက်တာနဲ့ C# က delegate ဆိုတာ ဘာလဲ ဆိုတာကို အနည်းငယ် သဘောပေါက်နိုင်မယ်ထင်တယ်။

    Delegate နဲ့ interface က ရောထွေးတတ်တယ်။

    Use a delegate when:
    - An eventing design pattern is used.
    - It is desirable to encapsulate a static method.
    - The caller has no need access other properties, methods, or interfaces on the object implementing the method.
    - Easy composition is desired.
    - A class may need more than one implementation of the method.
    
    Use an interface when:
    - There are a group of related methods that may be called.
    - A class only needs one implementation of the method.
    - The class using the interface will want to cast that interface to other interface or class types.
    - The method being implemented is linked to the type or identity of the class: for example, comparison methods.
    

    from : http://msdn.microsoft.com/en-us/library/ms173173(v=vs.80).aspx

Sign In or Register to comment.