C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet166/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   162   163   164   165   166   167   168   169   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Floors

,

Area

, and 

Occupants

. To access 

these variables, you will use the member access operator, which is a period. It is commonly 

referred to as the 



dot operator.

 The dot operator links the name of an object with the name of 

a member. The general form of the dot operator is shown here:

object

.

member

Thus, the 

object

 is specified on the left, and the 



member

 is put on the right. For example, to 

assign the 

Floors

 variable of 



house

 the value 2, use the following statement:

house.Floors = 2;

In general, you can use the dot operator to access both instance variables and methods.

Here is a complete program that uses the 

Building

 class:


// A program that uses the Building class.

using System;

www.freepdf-books.com



112

 

P a r t   I :  



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

class Building {

  public int Floors;    // number of floors

  public int Area;      // total square footage of building

  public int Occupants; // number of occupants

}

// This class declares an object of type Building.



class BuildingDemo {

  static void Main() {

    Building house = new Building(); // create a Building object

    int areaPP; // area per person

    // Assign values to fields in house.

    house.Occupants = 4;

    house.Area = 2500;

    house.Floors = 2;

    // Compute the area per person.

    areaPP = house.Area / house.Occupants;

    Console.WriteLine("house has:\n  " +

                      house.Floors + " floors\n  " +

                      house.Occupants + " occupants\n  " +

                      house.Area + " total area\n  " +

                      areaPP + " area per person");

  }


}

This program consists of two classes: 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   162   163   164   165   166   167   168   169   ...   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