I\'ve some library code that is used by both console and WPF apps. In the library code, there are some Console.Read()
calls. I only want to do those input rea
This SO question may provide you a solution.
Another solution is:
Console.Read()
returns -1
in windows forms applications without opening up a console window. In a console app, it returns the actual value. So you can write something like:
int j = Console.Read();
if (j == -1)
MessageBox.Show("It's not a console app");
else
Console.WriteLine("It's a console app");
I tested this code on console and winforms apps. In a console app, if the user inputs '-1', the value of j is 45. So it will work.