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
This shortcut will avoid exceptions being thrown when you use a composite formatting overload like Console.WriteLine(String, Object[])
and the number of format items in format
and the number of items in the argument list, args
, differ:
public bool WriteToConsole(string format, params object[] args)
{
var succeeded = false;
var argRegex = new Regex(@"\{\d+\}");
if ((args != null) && (argRegex.Matches(format).Count == args.Length))
{
Console.WriteLine(format, args);
succeeded = true;
}
else
{
Console.WriteLine(format);
}
return succeeded;
}