Make a shortcut for Console.WriteLine()
You could no doubt create a Visual Studio snippet for it (although actually there's one already for cw
, apparently - try it!).
I would personally suggest that you don't use a shortcut within the code - it's likely to be clearer to anyone reading it if it still says Console.WriteLine
.
Depending on what this is for, it may make sense to write a helper method called, say, Log
- that has a reasonable meaning, whereas CW
doesn't.
(If this is for logging, consider using something more powerful such as log4net, too.)
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.
Visual Studio already has a default code snippet for this. Just type cw
and press tab. Note that if you're considering using a method, it may lack some features like the automatic string.Format and other overloaded parameters.
If you are on .NET 3.5 or newer:
Action<string> cw = Console.WriteLine;
cw("Print Something");