/// <summary>
/// 发布器
/// </summary>
public class SBY
{
public delegate Boolean isSucceed(string message);
public event isSucceed DeliverNewspaper;
public Boolean GetResult(string dn)
{
if(DeliverNewspaper!=null)
{
DeliverNewspaper(dn);
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 订阅器
/// </summary>
public class TestEvent
{
static void Main(string[] args)
{
SBY sby = new SBY();
sby.DeliverNewspaper += (message) =>
{
if (!string.IsNullOrEmpty(message))
{
Console.WriteLine("A GetData");
return true;
}
else
{
Console.WriteLine("A don't GetData");
return false;
}
};
sby.DeliverNewspaper += (message) =>
{
if (!string.IsNullOrEmpty(message))
{
Console.WriteLine("B GetData");
return true;
}
else
{
Console.WriteLine("B don't GetData");
return false;
}
};
sby.GetResult("send the newspaper");
Console.ReadLine();
}
}
关于lambda的一个小例子
最新推荐文章于 2021-01-08 17:56:31 发布