C# 0 The Complete Reference


PART I C h a p t e r   6



Download 4,07 Mb.
Pdf ko'rish
bet200/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   196   197   198   199   200   201   202   203   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART I

C h a p t e r   6 :  

I n t r o d u c i n g   C l a s s e s   a n d   O b j e c t s  

135


PART IPART I

    this.Width = w;

    this.Height = h;

  }


  public int Area() {

    return this.Width * this.Height;

  }

}

class UseRect {



  static void Main() {

    Rect r1 = new Rect(4, 5);

    Rect r2 = new Rect(7, 9);

    Console.WriteLine("Area of r1: " + r1.Area());

    Console.WriteLine("Area of r2: " + r2.Area());

  }


}

Actually, no C# programmer would use 



this

 as just shown because nothing is gained 

and the standard form is easier. However, 

this

 has some important uses. For example, the 

C# syntax permits the name of a parameter or a local variable to be the same as the name of 

an instance variable. When this happens, the local name 



hides

 the instance variable. You can 

gain access to the hidden instance variable by referring to it through 

this

. For example, the 

following is a syntactically valid way to write the 

Rect( )

 constructor:

public Rect(int Width, int Height) {

  this.Width = Width;

  this.Height = Height;

}

In this version, the names of the parameters are the same as the names of the instance 



variables, thus hiding them. However, 

this

 is used to “uncover” the instance variables.

www.freepdf-books.com



This page intentionally left blank 

www.freepdf-books.com




7

Arrays and Strings

T

his chapter returns to the subject of C#’s data types. It discusses arrays and the 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   196   197   198   199   200   201   202   203   ...   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