程序集如下
using System; namespace ClassLibrary1 { public class Class1 { public delegate void ChangeDelegate(UInt16 value); public event ChangeDelegate changeEvent; private UInt16 _num; public UInt16 Num { get { return _num; } set { if (_num != value) changeEvent(value); _num = value; } } } }Class1.cs
using ClassLibrary1; using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { Class1 class1 = new Class1(); class1.changeEvent += Class1_changeEvent; class1.Num = 1; Console.ReadKey(); } private static void Class1_changeEvent(ushort value) { Console.WriteLine($"Num数值({value})发生了改变"); } } }Program.cs
运行结果
标签:类库,C#,UInt16,value,num,事件,changeEvent,public,Class1 From: https://www.cnblogs.com/lizhiqiang0204/p/16947552.html