How to call an extension method without using

后端 未结 7 1193
旧时难觅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条回答
  •  长情又很酷
    2021-01-03 22:59

    that is possible if Extension Method and class A in same namespace,

    If you have to use different namespaces then you have to use using, i don't think there is a way to do this without using. But you may reduce the number of using by putting all the extensions in one namespace like for Linq (System.Linq.Extensions)

    Note : You can remove the namespace for Extension methods, then it will make them globally available

提交回复
热议问题