using System;
class Program
{
static void Main(string[] args)
{
Bind b = new Bind();
b.cg += new Change((string str) => { Console.WriteLine("值已改变:" + str); });//绑定
while (true)
{
string str = Console.ReadLine();
b.Content = str;
}
}
}
public delegate void Change(string s);//委托
class Bind
{
public event Change cg;//事件
private string content;
public string Content
{
get { return content; }
set
{
if (content != value)
{
cg(value);//发起事件
}
content = value;
}
}
}
C#对某个变量进行单个监听即值改变回调
最新推荐文章于 2024-04-30 01:52:24 发布