return string variable from Main()
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.
Some decent ideas here: http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/a99a8b0d-fb49-4caf-8107-fc04bd48d3f9/
No, we can't return string from Main method. The entry point can optionally only return an int value. As, this return value is used in application termination (§10.2). or use void Main if you dont want to return.
精彩评论