Make a shortcut for Console.WriteLine()

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

    To piggyback on Michael Stum's answer, we could also make object as the type parameter to Action delegate like so:

    Action cw = x => Console.WriteLine(x.ToString());
    
    

    I usually do that on my C# Interactive window to quickly print out objects that I'm working with.

    For example:

    > var grid = driver.FindElements(By.XPath("//div[@class='ReactVirtualized__Grid__innerScrollContainer']//div"));
    > cw(grid);
    System.Collections.ObjectModel.ReadOnlyCollection`1[OpenQA.Selenium.IWebElement]
    > 
    

    提交回复
    热议问题