c#委托调用另一窗口函数
Prerequisite: Delegates in C#
先决条件: C#中的代表
We can also call a member function of a class using delegates. It is similar to static function calls, here we have to pass member function using an object on the creation of delegate.
我们还可以使用委托来调用类的成员函数。 它类似于静态函数调用,这里我们必须在创建委托时使用对象传递成员函数。
Program:
程序:
using System;
using System.Collections;
public delegate void myDelegates();
class Sample
{
public void fun()
{
Console.WriteLine("Call a member function using delegate");
}
}
class Program
{
static void Main()
{
Sample S = new Sample();
myDelegates del = new myDelegates(S.fun);
del();
}
}
Output
输出量
Call a member function using delegate
In above example, we created the class Sample, Sample class contains a member function name fun(). And then, we created another class Program than contains Main() function. Here, we created delegate reference and passed member function using Sample class object.
在上面的例子中,我们创建的类样品 , 样品类包含一个成员函数名的乐趣()。 然后,我们创建了另一个包含Main()函数的类Program。 在这里,我们创建了委托引用,并使用Sample类对象传递了成员函数。
翻译自: https://www.includehelp.com/dot-net/calling-member-function-using-delegates-in-c-sharp.aspx
c#委托调用另一窗口函数