扩展方法的 3 个要求:
- 声明扩展方法的类必须声明为
static
; - 扩展方法本身必须声明为
static
; - 扩展方法第一个参数类型前一定要包含关键字
this
。
输出:
MyMethod
类 和 ExtensionMythod
类的访问等级要一样,都为 public
或者 都为 internal
。
扩展方法也可以跟泛型结合起来使用。
参考:
《图解教程》 -> P145, P322
扩展方法的 3 个要求:
static
;static
;this
。输出:
MyMethod
类 和 ExtensionMythod
类的访问等级要一样,都为 public
或者 都为 internal
。
扩展方法也可以跟泛型结合起来使用。
参考:
《图解教程》 -> P145, P322
上一篇:三菱PLC|星-三角启动
al修饰的静态成员;6.只能包含静
Dc...
C#中可以定义扩展方法,还可以为集合做扩展方法。示例如下:[代码]注意:1 C# 只
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M