C# Extension methods in .NET 2.0

后端 未结 5 1853
走了就别回头了
走了就别回头了 2021-01-13 16:05

I have found several links to methods of making extension methods work in .NET2.0 (The moth, Discord & Rhyme, Stack Overflow). I have also heard vaguely from a colleague

5条回答
  •  悲&欢浪女
    2021-01-13 16:23

    The difference is simple enough:

    In your first example, you can put the attribute anywhere. In the second example, you can only apply it to a method, never more than one to the same method and an inherited class with the method overridden will not inherit the attribute. In the third example, you can apply it to a method, a class or an assembly.

    If you try to apply it in any other place, you will get a compiler error.

    The second seems to make most sense.

提交回复
热议问题