Make a shortcut for Console.WriteLine()

前端 未结 14 1429
北恋
北恋 2020-12-23 19:55

I have to type Console.WriteLine() many times in my code. Is it possible to create a shortcut for Console.WriteLine so that I can use it like...

CW=Console.Wr         


        
相关标签:
14条回答
  • 2020-12-23 20:39

    If you are on .NET 3.5 or newer:

    Action<string> cw = Console.WriteLine;
    
    cw("Print Something");
    
    0 讨论(0)
  • 2020-12-23 20:46

    C# 6 adds the using static feature:

    using static System.Console;
    
    class Program {
      void Main(string[] args) {
         WriteLine("Hello, {0}!", "world");
      }
    }
    

    IntelliSense in Visual Studio 2015 understands this new syntax.

    0 讨论(0)
提交回复
热议问题