main函式返回值的處理

iamzxf發表於2015-03-09


using System;

namespace CSharp.chapter01
{
	class Program
	{
		static int Main(String []args)
		{
			if(args.Length==0){
				Console.WriteLine("input one parameter:");
				return 1;
			}else{
				Console.WriteLine("hello, {0}", args[0]);
				return 0;
			}				
		}
	}
}

上述程式寫完後,可以通過批處理檔案進行呼叫,相關程式碼如下所示:

@echo off

mainValue
@if "%ERRORLEVEL%"=="0" goto good1
:fail1
	echo Execution failed
	echo return value=%ERRORLEVEL%
	goto end1
:good1
	echo Execution success
	echo return value=%ERRORLEVEL%
	goto end1
:end1


mainValue 12 23

@if "%ERRORLEVEL%"=="0" goto good0
:fail0
	echo Execution failed
	echo return value=%ERRORLEVEL%
	goto end0
:good0
	echo Execution success
	echo return value=%ERRORLEVEL%
	goto end0
:end0


相關文章