事件不会真正起作用我猜…
例如:
FootballTeam A = new FootballTeam();FootballTeam B = new FootballTeam();// Now A needs to let B kNow about it's manager change// manager is a property insIDe this class...解决方法 事件可能有效:
FootballTeam A = new FootballTeam();FootballTeam B = new FootballTeam();A.ManagerChanged += B.OnOtherManagerChanged;
事件的定义 – 当Football Manager的Manager属性更改值时,它会调用其OnManagerChanged方法:
class FootballTeam{ public event EventHandler ManagerChanged; protected virtual voID OnManagerChanged(EventArgs e) { EventHandler handler = ManagerChanged; if (handler != null) handler(this,e); } public voID OnOtherManagerChanged(object sender,EventArgs e) { FootballTeam otherTeam = (FootballTeam) sender; // A manager changed on a different FootballTeam instance // ...do something here }}总结
以上是内存溢出为你收集整理的c#类实例通信全部内容,希望文章能够帮你解决c#类实例通信所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)