Using Environment.ExitCode versus returning int from Main

后端 未结 3 1114
离开以前
离开以前 2021-01-04 07:23

I am planning to use the return code of the C# executable in one of my shell script. I have two options:

Returning a int value from the main method<

3条回答
  •  不知归路
    2021-01-04 08:14

    The difference lies when you need to handle the event on a parent application based on exit status of another application. Return is primarily used within an application, while exit is used to suddenly end an application. Here exit status can be used by another application to decide on its next steps.

    A return is used when you are returning a value to another function from where the code is called. or to indicate the end of code execution on some event.

    You can also see it like this:

    1) A return ends a function, which could be main(); an exit is used to end the program.

    2) Ending a program with a certain return value does cannot be interpreted implicitly by another application, but exit status can be used to decide on a code implementation.

提交回复
热议问题