本文介绍了C#中的代表和事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在哪种情况下我们基本上使用dot net.plz中的委托解释我的实例。In which scenario we basicaly use delegate in dot net.plz explain me with live example.推荐答案// Create a method for a delegate.public static void DelegateMethod(string message){ System.Console.WriteLine(message);} 现在声明并打电话..And now declare and just call..// Instantiate the delegate.Del handler = DelegateMethod;// Call the delegate.handler("Hello World"); 使用代表的一些范围: 1。事件处理程序(用于GUI等) 2。 启动线程 3。回调(例如异步API) 4。 LINQ和类似(List.Find等) 5。我想在其他任何地方有效地应用模板代码,里面有一些专门的逻辑(代表提供专业化) /> 您可以在此查看一些实时示例: 代表在C#中的权力 [ ^ ] C# - 代表101 - 一个实际例子 [ ^ ] http://stackoverflow.com/questions/2019402/when-why-to-use-delegates [ ^ ]Some scopes where delegates are used: 1. Event handlers (for GUI and more) 2. Starting threads 3. Callbacks (e.g. for async APIs) 4. LINQ and similar (List.Find etc) 5. Anywhere else where I want to effectively apply "template" code with some specialized logic inside (where the delegate provides the specialization)Some live examples you can view here:The Power of Delegates in C#[^]C# - Delegates 101 - A Practical Example[^]http://stackoverflow.com/questions/2019402/when-why-to-use-delegates[^] 这篇关于C#中的代表和事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-14 08:36