I am trying to create an overload of a method System.Console.ReadLine()that will take a string argument. My intention is basically to write
string s = Console.ReadLine("Please enter a number: ");
instead
Console.Write("Please enter a number: ");
string s = Console.ReadLine();
I don’t think that you can overload it Console.ReadLineyourself, so I tried to implement an inherited class, for example:
public static class MyConsole : System.Console
{
public static string ReadLine(string s)
{
Write(s);
return ReadLine();
}
}
This does not work because it is impossible to inherit from System.Console(because it is a static class that automatically creates a private class).
Does what I am trying to do here make sense? Or is it worth it to overload something from a static class?
source
share