C# 委托实例实现的多种类型
2024-09-03 23:47:46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication17
{
public delegate string testDelegate(string a, int b);
class Program
{
static void Main(string[] args)
{
//1 C# 1 最原始的委托赋值
testDelegate t1 = new testDelegate(M); //2 C# 2 委托赋值
testDelegate t2 = delegate (string a, int b)
{
Console.WriteLine(a + b.ToString());
return a + b.ToString();
}; //3 C# 3 委托赋值(a,b值类型对应委托声明的类型)
testDelegate t3 = (a, b) =>
{
Console.WriteLine(a + b.ToString());
return a + b.ToString();
};
// 调用委托实例
t1.Invoke("测试1", );
t2.Invoke("测试2", );
t3.Invoke("测试3", );
}
static string M(string a, int b)
{
Console.WriteLine(a + b.ToString());
return a + b.ToString();
}
}
}
最新文章
- js 页面无滚动条添加滚轮事件
- 「C++11」Lambda 表达式
- String.getBytes()
- 手动安装m4, autoconf, automake, libtool
- C++中typename关键字的用法
- Some SQL basics
- .NET设计模式系列文章 from TerryLee
- 通过Jasmine和Guard自动测试JavaScript
- jeecg自定义按钮使用exp属性不起作用
- 1013. Battle Over Cities 用dfs计算联通分量
- 最强大的跨语言调用生成工具:Swig 快速实用教程
- Django——日志
- sqlite--一秒20万数据
- VUE 实现复制内容到剪贴板功能
- TFS SDK
- 除虫记之C#调用C函数出现的诡异错误
- CentOS下iptables详解
- SharePoint 如何导出部署的场解决方案
- css3画半圆 , 加上一点动画
- Workbook对象的方法总结(二)