当前位置: 首页>>代码示例>>C#>>正文


C# MyDelegate类代码示例

本文整理汇总了C#中MyDelegate的典型用法代码示例。如果您正苦于以下问题:C# MyDelegate类的具体用法?C# MyDelegate怎么用?C# MyDelegate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MyDelegate类属于命名空间,在下文中一共展示了MyDelegate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    public static void Main()
    {
        MyDelegate a, b, c, d;

        // Create the delegate object a that references
        // the method Hello:
        a = new MyDelegate(Hello); // Ex A1 - Atribuição de Métodos
        // Create the delegate object b that references
        // the method Goodbye:
        b = new MyDelegate(Goodbye); // Ex A1 - Atribuição de Métodos
        // The two delegates, a and b, are composed to form c:
        c = a + b; // Ex A1 - Adição de Métodos
        // Remove a from the composed delegate, leaving d,
        // which calls only the method Goodbye:
        d = c - a; // Ex A1 - Subtração de métodos

        Console.WriteLine("Invoking delegate a:");
        a("A"); // Ex A1 - Invocação
        Console.WriteLine("Invoking delegate b:");
        b("B"); // Ex A1 - Invocação
        Console.WriteLine("Invoking delegate c:");
        c("C"); // Ex A1 - Invocação // Ex A2 - Não é garantida a ordem de invocação
        Console.WriteLine("Invoking delegate d:");
        d("D"); // Ex A1 - Invocação // Ex A2 - Não é garantida a ordem de invocação
        // Ex A6
        Console.WriteLine("Invoking method delegate:");
        callDelegate(a);

        Console.Read();
    }
开发者ID:jfloff,项目名称:PADI,代码行数:30,代码来源:exercicio-1.cs

示例2: btn_asyncTest_Click

        private void btn_asyncTest_Click(object sender, EventArgs e)
        {
            //Assign a function to the delegate
            myAsync = new MyDelegate(this.SomeFunction);

            myAsync.BeginInvoke(5, 10, null, null);
        }
开发者ID:Tjornfelt,项目名称:WindowsFormsSchoolProject,代码行数:7,代码来源:WindowsForms.cs

示例3: Forget

 public void Forget(string eventName, MyDelegate subscriber)
 {
     if (events.Keys.Contains(eventName))
     {
         events[eventName] -= subscriber;
     }
 }
开发者ID:CTMarak,项目名称:CMP129,代码行数:7,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            MyClass obj = new MyClass();
            MyDelegate del1 = new MyDelegate(obj.Func1);
            del1 += new MyDelegate(obj.Func2);

            //上面两句可以简写为以下形式:
            //MyDelegate del1 = obj.Func1;
            //del1 += obj.Func2;

            Delegate[] ds;

            ds = del1.GetInvocationList();
            Console.WriteLine("del1的委托调用列表中包含{0}个方法", ds.GetLength(0));

            del1(5); //先调用obj1.Func1(),再调用obj1.Func2()

            MyDelegate del2 = new MyDelegate(obj.Func1);
            del2 += new MyDelegate(obj.Func2);

            //组合委托

            Delegate mul = del1 + del2;
            ds = mul.GetInvocationList();
            Console.WriteLine("mul的委托调用列表中包含{0}个方法", ds.GetLength(0));
            int ret = (mul as MyDelegate)(10); //获取委托调用列表最后一个方法的返回值

            Console.WriteLine("ret = {0}", ret);

            Console.ReadKey();
        }
开发者ID:ningboliuwei,项目名称:CSharp----_---,代码行数:31,代码来源:Program.cs

示例5: SystemReflectionType_ObjectGetType_Test0

        public MFTestResults SystemReflectionType_ObjectGetType_Test0()
        {
            bool fRes = true;

            ///
            /// Test object.GetType method for various types (including
            /// reflection types and arrays of reflection types).
            /// 
            object o = (object)1;
            fRes &= (o.GetType() == typeof(int));

            o = (object)typeof(Type);
            fRes &= o.GetType() == typeof(Type).GetType();

            o = AppDomain.CurrentDomain.GetAssemblies();
            fRes &= o.GetType() == typeof(Assembly[]);

            o = new TestClass();
            fRes &= o.GetType() == typeof(TestClass);

            o = new TestStruct();
            fRes &= o.GetType() == typeof(TestStruct);

            o = new MyDelegate(MyDelegateImpl);
            fRes &= o.GetType() == typeof(MyDelegate);

            o = (new MyDelegate(MyDelegateImpl)).Method;
            Debug.Print("object (MethodInfo) GetType: " + o.GetType().ToString());

            MethodInfo mi = typeof(SystemReflectionTypeTests).GetMethod("MyDelegateImpl", BindingFlags.Static | BindingFlags.NonPublic);
            fRes &= o.GetType() == mi.GetType();

            return fRes ? MFTestResults.Pass : MFTestResults.Fail;
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:34,代码来源:SystemReflectionTypeTests.cs

示例6: TestCombineRemove

	public void TestCombineRemove()
	{
		MyDelegate dela = new MyDelegate( MethodA );
		MyDelegate delb = new MyDelegate( MethodB );
		MyDelegate delc = new MyDelegate( MethodC );
		MyDelegate deld = new MyDelegate( MethodD );

		string val;
		char res;

		// test combine
		MyDelegate del1, del2;
		del1 = dela + delb + delb + delc + delb + delb + deld;
		val = "";
		res = del1( ref val );
		Assert.AreEqual("abbcbbd", val , "#A01");
		Assert.AreEqual('d', res , "#A02");

		// test remove
		del2 = del1 - ( delb + delb );
		val = "";
		res = del2( ref val );
		Assert.AreEqual("abbcd", val , "#A03");
		Assert.AreEqual('d', res , "#A04");

		// we did not affect del1, did we?
		val = "";
		res = del1( ref val );
		Assert.AreEqual("abbcbbd", val , "#A05");
	}
开发者ID:Xtremrules,项目名称:dot42,代码行数:30,代码来源:MulticastDelegateTest_Mono.cs

示例7: DelegateTimer

 public DelegateTimer(DelegateTimerKey key, MyDelegate d, float remainTime)
 {
     mTimerKey = key;
     mDelegate = d;
     mTime = remainTime;
     mRemainTime = remainTime;
 }
开发者ID:Raymenes,项目名称:Rui_Zeng_Portfolio,代码行数:7,代码来源:DelegateTimer.cs

示例8: Main

    public static void Main()
    {
        MyDelegate a, b, c, d;

        // Create the delegate object a that references
        // the method Hello:
        a = new MyDelegate(Hello);
        // Create the delegate object b that references
        // the method Goodbye:
        b = new MyDelegate(Goodbye);
        // The two delegates, a and b, are composed to form c:
        c = a + b;
        // Remove a from the composed delegate, leaving d,
        // which calls only the method Goodbye:
        d = c - a;

        Console.WriteLine("Invoking delegate a:");
        a("A");
        Console.WriteLine("Invoking delegate b:");
        b("B");
        Console.WriteLine("Invoking delegate c:");
        c("C");
        Console.WriteLine("Invoking delegate d:");
        d("D");
    }
开发者ID:dpgit,项目名称:TutorialIntermediate,代码行数:25,代码来源:compose.cs

示例9: Main

        static void Main(string[] args)
        {
            MyDelegate arithmethod = null;
            Console.WriteLine("Please insert two integer numbers");

                int input1 = Convert.ToInt32(Console.ReadLine());
                int input2 = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("Please choose your operation as + , - , * , M");
                char operationinput = Convert.ToChar(Console.ReadLine());
                switch (operationinput)
                {
                    case '+':
                        arithmethod = new MyDelegate(Add);
                        break;
                    case '-':
                        arithmethod = new MyDelegate(Subtrac);
                        break;
                    case '*':
                        arithmethod = new MyDelegate(Multiply);
                        break;
                    case 'M':
                        arithmethod = new MyDelegate(Max);
                        break;

                }

                int r = arithmethod(input1, input2);
                Console.WriteLine("The result of your {0} operation is {1}", operationinput, r);

            Console.ReadLine();
        }
开发者ID:payam49er,项目名称:experiments,代码行数:32,代码来源:Program.cs

示例10: Main

 static void Main(string[] args)
 {
     deli = new MyDelegate(MyMethod);
     Console.WriteLine("Invoking the method...");
     result = deli.BeginInvoke(MyMethodEnds, null);
     Console.WriteLine("Reached Console.ReadKey()");
     Console.ReadKey();
 }
开发者ID:oblivious,项目名称:Oblivious,代码行数:8,代码来源:Program.cs

示例11: Main

   public static void Main(){
      MyDelegate call = new MyDelegate(FirstMethod);
      call += new MyDelegate(SecondMethod);
 
      call("Message A");
      call("Message B");
      call("Message C");
   }
开发者ID:snellj,项目名称:code,代码行数:8,代码来源:p8-delegate.cs

示例12: Run

        public void Run()
        {
            MyStruct s = new MyStruct();
            s.b = "OK";

            MyDelegate dg = new MyDelegate(s.Test);
            dg();
        }
开发者ID:elasota,项目名称:clarity,代码行数:8,代码来源:TestStructDelegate.cs

示例13: neuDelegate

 public MyDelegate neuDelegate()
 {
     Class1 c2 = new Class1();
                             MyDelegate d1 = new MyDelegate(c2.delegateMethod1);
                             MyDelegate d2 = new MyDelegate(c2.delegateMethod2);
                             MyDelegate d3 = d1 + d2;
                             return d3;
 }
开发者ID:amigodornot666,项目名称:mono-cs,代码行数:8,代码来源:delegate1.cs

示例14: MyDelegate

 delegate string MyDelegate();//声明委托
 static void Main(string[] args)
 {
     Helloworld hello = new Helloworld();
     MyDelegate h = new MyDelegate(hello.HelloCN);
     Console.WriteLine(h());
     h = new MyDelegate(hello.HelloEN);
     Console.WriteLine(h());
 }
开发者ID:icegithub,项目名称:csharp-exercise,代码行数:9,代码来源:Program.cs

示例15: Subscribe

 public void Subscribe(string eventName, MyDelegate subscriber)
 {
     if (!events.Keys.Contains(eventName))
     {
         events.Add(eventName, null);
     }
     events[eventName] += subscriber;
 }
开发者ID:CTMarak,项目名称:CMP129,代码行数:8,代码来源:Program.cs


注:本文中的MyDelegate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。