Make a shortcut for Console.WriteLine()

前端 未结 14 1454
北恋
北恋 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:36

    If you want it global, you could write an extension method:

    public static class StringExtensions
    {
       public static void ConLog(this string msg)
       {
         Console.WriteLine(msg);
       }
    }
    

    Now wherever you are, you can call "My Message".ConLog(); on any string in your application and write it to the console.

提交回复
热议问题