Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of delegation and event examples in C #

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

The editor of this article introduces "delegation and event case analysis in C#" in detail, with detailed content, clear steps and proper handling of details. I hope this article "delegation and event case analysis in C#" can help you solve your doubts. Let's follow the editor's train of thought to learn new knowledge.

1. Define delegate delegate void StudentDelegate (); / / [1] define a delegate 2, define a class that invokes and define events / define events and invoke events must be placed in a class / class InvokeDefine / / [2] define a class {public event StudentDelegate StudentEvent that invokes and defines events Public void Invoke () {StudentEvent?.Invoke (); / / .Null check operator}} III, subscriber class EventFunction / / [3] subscriber {public void Student1 () {Console.WriteLine ("I am subscriber 1") } public void Student2 () {Console.WriteLine ("I am a subscriber 2");}} IV. Subscription event static void Main (string [] args) {EventFunction eventFunction = new EventFunction (); InvokeDefine invokeDefine = new InvokeDefine (); invokeDefine.StudentEvent + = eventFunction.Student1 / / [4] subscription event invokeDefine.StudentEvent + = eventFunction.Student2; invokeDefine.Invoke (); Console.ReadKey () } after reading this, the article "delegation and event example Analysis in C#" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report