I would like to return a string variable from my Main() method. I’ve returned int variables. But I’m not sure if it’s possible to return a string variable from Main() when you exit the program?
Any ideas?
Here is my int code:
public class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static int Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
int error = 1;
return error;
}
}
If I change int to string, I get this error: Program does not contain a static ‘Main’ method suitable for an entry point. So obviously this is not allowed. What is the correct approach?
No you cannot return a string. What you can do on the other hand is write the string to the standard output and then from the program that’s calling this program capture that output.