Monday, 27 August 2012

c# tutorial

A delegate is a variable that holds a function.


namespace delegateexample1
{
    delegate string[] mydelegate(string str);

    class Program
    {
     
        static void Main(string[] args)
        {
            mydelegate mymy = new mydelegate(testdeligate.replacestring);
            mydelegate mimi = new mydelegate(testdeligate.splitstringup);

            string[] str= mymy("Ade is a good boy");
            string[] str1 = mimi("Ayo is a nice boy");
            foreach (string x in str)
            {
                Console.WriteLine("\t\n{0}", x);
            }
            Console.WriteLine("\t ");
            foreach (string x in str1)
            {
                Console.WriteLine("\t\n{0}", x);
            }
            Console.ReadLine();
           
        }
        class testdeligate
        {
           
            public static string[] replacestring(string s)
            {
                string[] marray = s.Split(' ');
                //StringSplitOptions option=new StringSplitOptions();
                //Console.WriteLine("Replace Space with Hyphen...");
                //return s.Split(marray, option);
                //return s.Replace(' ','-');
                return marray;
            }
            public static string[] splitstringup(string s)
            {
                 string[] hiarray = s.Split(' ');
                 return hiarray;
            }
        }
      

No comments:

Post a Comment