事件其實就是特殊的委託,我用委託寫了個例子給你參考一下。
class Program
{
static void Main(string[] args)
var w = new Work
OnNotify = i => Console.Write(i)
};
w.Do();
//輸出 0123456789
Console.Read();
}
public class Work
//定義一個無返回值的泛型委託
public Action
public void Do()
for (var i = 0; i
if (OnNotify != null)
OnNotify(i);
事件其實就是特殊的委託,我用委託寫了個例子給你參考一下。
class Program
{
static void Main(string[] args)
{
var w = new Work
{
OnNotify = i => Console.Write(i)
};
w.Do();
//輸出 0123456789
Console.Read();
}
}
public class Work
{
//定義一個無返回值的泛型委託
public Action
public void Do()
{
for (var i = 0; i
{
if (OnNotify != null)
{
OnNotify(i);
}
}
}
}