C# 0 The Complete Reference


balance  is  null



Download 4,07 Mb.
Pdf ko'rish
bet763/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   759   760   761   762   763   764   765   766   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

balance

 is 


null

. This causes 



currentBalance

 to be 


assigned the value 0.0 and no exception will be thrown.

double? balance = null;

double currentBalance;

currentBalance = balance ?? 0.0;

In the next sequence, 

balance

 is given the value 123.75:

double? balance = 123.75;

double currentBalance;

currentBalance = balance ?? 0.0;

Now, 


currentBalance

 will contain the value of 



balance

, which is 123.75.

One other point: The right-hand expression of the 

??

 is evaluated only if the left-hand 

expression does not contain a value. The following program demonstrates this fact:

// Using ??

using System;

class NullableDemo2 {

www.freepdf-books.com



602

 

P a r t   I :  



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

  // Return a zero balance.

  static double GetZeroBal() {

    Console.WriteLine("In GetZeroBal().");

      return 0.0;

  }


  static void Main() {

    double? balance = 123.75;

    double currentBalance;

    // Here, GetZeroBal( ) is not called because balance

    // contains a value.

    currentBalance = balance ?? GetZeroBal();

    Console.WriteLine(currentBalance);

  }


}

In this program, the method 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   759   760   761   762   763   764   765   766   ...   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