Use of “this” keyword in formal parameters for static methods in C#

前端 未结 6 1271
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 09:20

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

6条回答
  •  一个人的身影
    2020-11-27 09:49

    In addition to Preet Sangha's explanation:
    Intellisense displays the extension methods with a blue arrow (e.g. in front of "Aggregate<>"):

    enter image description here

    You need a

    using the.namespace.of.the.static.class.with.the.extension.methods;
    

    for the extension methods to appear and to be available, if they are in a different namespace than the code using them.

提交回复
热议问题