Reputation: 177
During my job interview, interviewer asked me to change the the console output to print "B" without touching the main method and console!
is this possible? (I tried to change the entry point,but it was not correct)
I have no idea how to answer this question
class Program
{
static void Main(string[] args)
{
Console.WriteLine("A");
}
}
Upvotes: 3
Views: 559
Reputation: 8921
Well, your interviewer said you can't touch the console. He didn't say you can't make a new one.
public static class Console
{
public static void WriteLine(string dontCare)
{
//Specify System.Console instead of just Console
System.Console.WriteLine("B");
}
}
public static class Program
{
public static void Main(string[] args)
{
Console.WriteLine("A");
}
}
Alternatively, you can go through with your idea, which was to make a new Main
method, which prints "B" to the console. For that to work, you just have to tell the compiler which one to actually use. This thread details several ways of doing that.
Upvotes: 5