c# - C# 中的通用部分方法?
问题描述
部分类和部分方法状态:
部分方法可以是通用的。约束放在定义的部分方法声明上,并且可以选择在实现的部分上重复。实现声明中的参数和类型参数名称不必与定义声明中的相同。
"Constraints are put on the defining partial method declaration, and may optionally be repeated on the implementing one."
视觉上和的代码示例是"Parameter and type parameter names do not have to be the same in the implementing declaration as in the defining one."
什么?
我不知道上面 2 个语句在代码中的视觉效果如何。
解决方案
宣言
包括通用约束:
public void Method<TName>(int name) where T : class;
执行
没有重复的通用约束和不同的参数名称(但相同的签名):
public void Method<TOther>(int other)
{
// ....
}
推荐阅读
- html - 字体未加载,但 URL 指向良好
- openvms - OpenVMS - 尝试为无效选择创建操作
- mysql - 有人搜索 NULL 对象时的响应
- php - 如何从视图将参数传递给模型函数?
- powershell - 如何在PowerShell中的多个文件夹中递归更改名称
- python - 在“基线”图上绘制点,每次迭代
- angular - Angular-SpringBoot 下载 excel 文件 HttpErrorResponse
- c++ - 在 C++ 中创建 pacman 碰撞检测的困难
- jquery - 将输入中的数字附加到href
- php - 如何使用 PHP PDO 跨平台进行用户名/密码管理