C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet568/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   564   565   566   567   568   569   570   571   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

EXPERIMENTAL

 and 


TRIAL

. The second 



WriteLine( )

 statement is compiled only if both are defined.

You can use the ! to compile code when a symbol is not defined. For example,

#if !EXPERIMENTAL

  Console.WriteLine("Code is not experimental!");

#endif


The call to 

WriteLine( )

 will be compiled only if 



EXPERIMENTAL

has not

 been defined.

www.freepdf-books.com



454

 

P a r t   I :  



T h e   C #   L a n g u a g e

#else and #elif

The


#else

 directive works much like the 



else

 that is part of the C# language: It establishes an 

alternative if 

#if

 fails. The previous example can be expanded as shown here:

// Demonstrate #else.

#define EXPERIMENTAL

using System;

class Test {

  static void Main() {

    #if EXPERIMENTAL

      Console.WriteLine("Compiled for experimental version.");

    #else

      Console.WriteLine("Compiled for release.");

    #endif

    #if EXPERIMENTAL && TRIAL

       Console.Error.WriteLine("Testing experimental trial version.");

    #else

       Console.Error.WriteLine("Not experimental trial version.");

    #endif

    Console.WriteLine("This is in all versions.");

  }

}

The output is shown here:



Compiled for experimental version.

Not experimental trial version.

This is in all versions.

Since


TRIAL

 is not defined, the 



#else

 portion of the second conditional code sequence is 

used.

Notice that 



#else

 marks both the end of the 



#if

 block and the beginning of the 



#else

block. This is necessary because there can only be one 



#endif

 associated with any 



#if

.

Furthermore, there can be only one 



#else

 associated with any 



#if

.

The



#elif

 directive means “else if” and establishes an if-else-if chain for multiple 

compilation options. 

#elif

 is followed by a symbol expression. If the expression is true, that 

block of code is compiled and no other 

#elif

 expressions are tested. Otherwise, the next 

block in the series is checked. If no 

#elif

succeeds, then if there is a 



#else

, the code sequence 

associated with the 

#else

is compiled. Otherwise, no code in the entire 



#if

is compiled.

The general form for 

#elif

 is


#if

symbol-expression

 statement 

sequence

#elif


symbol-expression

 statement 

sequence

#elif


symbol-expression

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   564   565   566   567   568   569   570   571   ...   1096




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