How to call an extension method without using

后端 未结 7 1171
旧时难觅i
旧时难觅i 2021-01-03 22:37
using System;

class Runner
{
    static void Main()
    {
        A a = new A();
        // how to say a.PrintStuff() without a \'using\'
        Console.Read();
           


        
7条回答
  •  萌比男神i
    2021-01-03 23:06

    It needs the using to know where the function lives. One example of this in Linq. Without the System.Linq using - you won't have linq enabled for any of your IEnumerable's

    However, you can define the extension method in the same namespace as the caller to avoid putting in a using. This approach will however not work if it's needed in many namespaces

提交回复
热议问题