C# 0 The Complete Reference


set  accessor as  private



Download 4,07 Mb.
Pdf ko'rish
bet345/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   341   342   343   344   345   346   347   348   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

set

 accessor as 



private

. For example, here is a property called 



MyProp

 that has its 



set

 accessor specified 

as

private

.

// Use an access modifier with an accessor.



using System;

class PropAccess {

  int prop; // field being managed by MyProp

  public PropAccess() { prop = 0; }

  /* This is the property that supports access to

     the private instance variable prop. It allows

     any code to obtain the value of prop, but only

     other class members can set the value of prop. */

  public int MyProp {

    get {

      return prop;

    }


    private set { // now, private

      prop = value;

    }

  }


www.freepdf-books.com


262

 

P a r t   I :  



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

  // This class member increments the value of MyProp.

  public void IncrProp() {

    MyProp++; // OK, in same class.

  }

}

// Demonstrate accessor access modifier.



class PropAccessDemo {

  static void Main() {

    PropAccess ob = new PropAccess();

    Console.WriteLine("Original value of ob.MyProp: " + ob.MyProp);

//    ob.MyProp = 100; // can't access set

    ob.IncrProp();

    Console.WriteLine("Value of ob.MyProp after increment: "

                      + ob.MyProp);

  }

}

In the 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   341   342   343   344   345   346   347   348   ...   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