Use of “this” keyword in formal parameters for static methods in C#
来源:互联网 发布:大数据與1040 编辑:程序博客网 时间:2024/06/04 18:45
http://stackoverflow.com/a/846773/2177408
I've come across several instances of C# code like the following:
public static int Foo(this MyClass arg)
I haven't been able to find an explanation of what the this
keyword means in this case. Any insights?
Answer:
This is an extension method. See here for an explanation.
it means that you can call
MyClass myClass = new MyClass();int i = myClass.Foo();
rather than
MyClass myClass = new MyClass();int i = Foo(myClass);
This allows the construction of fluent interfaces as stated below.
0 0
- Use of “this” keyword in formal parameters for static methods in C#
- HCI Issues - Formal Methods in HCI
- static keyword in C
- Cannot use this in a static context
- Cannot use this in a static context
- Cannot use this in a static context
- Cannot use this in a static context
- Cannot use this in a static context
- Class for the use of RegQueryInfoKey pinvoke interop in C#
- Java - Static keyword in Java
- Use MFC in a Static Library,This may be due to a corruption of the heap....
- the this keyword in javascript
- When to Use Static Classes in C#
- The implementation of anonymous methods in C# and its consequences
- Can you override Static Methods in Java?
- Can you override Static Methods in Java?
- Interface in Java 8(Default/Static methods)
- Use Static Method in Powershell
- 变量声明和定义的区别
- iOS 预留贴
- 旋转链表
- Java基础视频教程第15天_集合之TreeSet、泛型
- programming error (function overloading)
- Use of “this” keyword in formal parameters for static methods in C#
- PHP入门-表单处理问题总结
- Class constructor
- C++ overloading contructor
- C++ classes and uniform initialization
- 各大公司中印员工比例
- 第50题 Longest Palindromic Substring
- 蚆螇肄莈蒅蚀肀肅莅蚃膅芄
- 芃葿螆罿莂薁蕿袅莂芁螅螁