Search code examples
c#visual-studio-2017console-application

It is possible to write only WriteLine instead of Console.WriteLine in C#?


I'm a completely noob and a begginer programmer in C# but I was reading about Roslyn and 'What's new in C# 7.0' and I found something very interesting that I can't find out the answer I need.

In this link, all the examples given contain something like WriteLine("something"); instead of Console.WriteLine("something");, for example:

public void PrintCoordinates(Point p)
{
  p.GetCoordinates(out int x, out int y);
  WriteLine($"({x}, {y})");
}

My question is: How can I do that?

Would something like this work?

public static void WriteLine(string v) => Console.WriteLine(v);

Solution

  • Try using static directive:

     using static System.Console;
    
     ...
    
     WriteLine("some text");