This print for content only-size & color not accurate 7" X 9-1/4" / casebound / malloy


// Note we are now returning an int, rather than void



Download 21,46 Mb.
Pdf ko'rish
bet179/1830
Sana28.09.2021
Hajmi21,46 Mb.
#188411
1   ...   175   176   177   178   179   180   181   182   ...   1830
Bog'liq
[book] [en] Pro C# 2008 and the NET 3.5 Platform Fourth Edition

// Note we are now returning an int, rather than void.

static int Main(string[] args)

{

// Display a message and wait for Enter key to be pressed.

C H A P T E R   3  



C O R E   C #   P R O G R A M M I N G   C O N S T R U C T S, PA RT   I



71

8849CH03.qxd  9/24/07  11:07 AM  Page 71




Console.WriteLine("***** My First C# App *****");

Console.WriteLine("Hello World!");

Console.WriteLine();

Console.ReadLine();



// Return an arbitrary error code.

return -1;

}

Let’s now capture Main()’s return value with the help of a batch file. Using the Windows



Explorer, navigate to the folder containing your compiled application (for example,

C:\SimpleCSharpApp\bin\Debug). Add a new text file (named SimpleCSharpApp.bat) to the

Debug folder that contains the following instructions (if you have not authored *.bat files

before, don’t concern yourself with the details; this is a test . . . this is only a test):

@echo off

rem A batch file for SimpleCSharpApp.exe

rem which captures the app's return value.

SimpleCSharpApp

@if "%ERRORLEVEL%" == "0" goto success

:fail


echo This application has failed!

echo return value = %ERRORLEVEL%

goto end

:success


echo This application has succeeded!

echo return value = %ERRORLEVEL%

goto end

:end


echo All Done.

At this point, open a command prompt and navigate to the folder containing your executable

and new *.bat file (again, for example, C:\SimpleCSharpApp\bin\Debug). Execute the batch logic

by typing its name and pressing the Enter key. You should find the following output, given that your

Main() method is returning -1 (see Figure 3-1). Had the Main() method returned 0, you would see

the message “This application has succeeded!” print to the console.



Figure 3-1.

Capturing an application’s return value via a batch file

Again, a vast majority (if not all) of your C# applications will use void as the return value from

Main(), which as you recall implicitly returns the error code of zero. To this end, the Main() methods

C H A P T E R   3  



C O R E   C #   P R O G R A M M I N G   C O N S T R U C T S, PA RT   I



72

8849CH03.qxd  9/24/07  11:07 AM  Page 72




used in this text will indeed return void (and the remaining projects will certainly not need to make

use of batch files to capture return codes!).




Download 21,46 Mb.

Do'stlaringiz bilan baham:
1   ...   175   176   177   178   179   180   181   182   ...   1830




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish