您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C# 中的泛型委托是什么?

2026/1/7 2:24:46发布41次查看
使用通用委托,您不需要定义委托语句。它们在系统命名空间中定义。
您可以使用类型参数定义通用委托。例如 -
delegate t mydelegete<t>(t n);
示例以下示例展示了如何在 c# 中创建通用委托 -
using system;using system.collections.generic;delegate t mydelegete<t>(t n);namespace genericdelegateappl { class testdelegate { static int num = 5; public static int addnum(int p) { num += p; return num; } public static int multnum(int q) { num *= q; return num; } public static int getnum() { return num; } static void main(string[] args) { //create delegate instances numberchanger nc1 = new numberchanger(addnum); numberchanger nc2 = new numberchanger(multnum); //calling the methods using the delegate objects nc1(50); console.writeline("value of num: {0}", getnum()); nc2(10); console.writeline("value of num: {0}", getnum()); console.readkey(); } }}
以上就是c# 中的泛型委托是什么?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product