How to return a code number to system in C#?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hello,

I'm new to C# so forgive me for a simple/silly question. In C/C++ you can return a different code number if an error has occurred, for example:

int main() {
....
if (someError)
return 3; // 3 may mean a specific error
....
return 0; // 0 == successful
}

how can this be done in C#? Whatever I do in the C# code, it seems that the system and applications calling the C# application get code 0.

thanks
 
RafaelC said:
I'm new to C# so forgive me for a simple/silly question. In C/C++ you
can return a different code number if an error has occurred, for
example:

int main() {
...
if (someError)
return 3; // 3 may mean a specific error
...
return 0; // 0 == successful
}

how can this be done in C#? Whatever I do in the C# code, it seems
that the system and applications calling the C# application get code
0.

The above (just changing the case) should work fine, but an alternative
is to use Environment.Exit.

An example of the "easy" way:

using System;

class Test
{
static int Main()
{
return 3;
}
}

Run the program and then print out %ERRORLEVEL% and it will be 3.
 
Hi Jon,

I was about to write a C++ app that would check the returned value, but is there any reason why VS .NET always shows that the application has exited with code 0 in the tab when debugging?
thanks
 
RafaelC said:
I was about to write a C++ app that would check the returned value,
but is there any reason why VS .NET always shows that the application
has exited with code 0 in the tab when debugging?

Don't know, I'm afraid :(
 
Back
Top