C# 0 The Complete Reference


Nullable Objects in Expressions



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

Nullable Objects in Expressions

A nullable object can be used in expressions that are valid for its underlying type. 

Furthermore, it is possible to mix nullable objects and non-nullable objects within the same 

expression. This works because of the predefined conversion that exists from the underlying 

type to the nullable type. When non-nullable and nullable types are mixed in an operation, 

the outcome is a nullable value.

The following program illustrates the use of nullable types in expressions:

// Use nullable objects in expressions.

using System;

class NullableDemo {

  static void Main() {

    int? count = null;

    int? result = null;

    int incr = 10; // notice that incr is a non-nullable type

    // result contains null, because count is null.

    result = count + incr;

    if(result.HasValue)

      Console.WriteLine("result has this value: " + result.Value);

    else

      Console.WriteLine("result has no value");

    // Now, count is given a value and result will contain a value.

    count = 100;

    result = count + incr;

www.freepdf-books.com




Download 4,07 Mb.

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