Make a shortcut for Console.WriteLine()

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

    You could declare a static method to wrap the call:

    static class C
    {
        static void W(string s)
        {
            Console.WriteLine(s);
        }
    }
    

    then:

    C.W("Print Something");
    

    I would be inclined to use the "inline method" refactoring before checking in any code that calls this method. As Jon Skeet notes, it's less confusing simply to use Console.WriteLine directly.

提交回复
热议问题