Overloading Console.ReadLine possible? (or any static class method)
- by comecme
I'm trying to create an overload of the System.Console.ReadLine() method that will take a string argument. My intention basically is to be able to write
string s = Console.ReadLine("Please enter a number: ");
in stead of
Console.Write("Please enter a number: ");
string s = Console.ReadLine();
I don't think it is possible to overload Console.ReadLine itself, so I tried implementing an inherited class, like this:
public static class MyConsole : System.Console
{
public static string ReadLine(string s)
{
Write(s);
return ReadLine();
}
}
That doesn't work though, cause it is not possible to inherit from System.Console (because it is a static class which automatically makes is a sealed class).
Does it make sense what I'm trying to do here? Or is it never a good idea to want to overload something from a static class?