How to call an extension method without using

后端 未结 7 1172
旧时难觅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:43

    You can add extensions method without namespace. This will affect the whole systems which is not recommended.

    public static class StringExtensions
    {       
        public static void HelloWorld(this String s)
        {
            Console.Write("Hello World");
        }
    }
    
    
    
        string str = "s";
        str.HelloWorld();
    

提交回复
热议问题