C# 0 The Complete Reference


PART I C h a p t e r   1 7



Download 4,07 Mb.
Pdf ko'rish
bet594/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   590   591   592   593   594   595   596   597   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART I

C h a p t e r   1 7 :  

R u n t i m e   T y p e   I D ,   R e f l e c t i o n ,   a n d   A t t r i b u t e s  

475


PART IPART I

The output is shown here:

Available constructors:

   MyClass(Int32 i)

   MyClass(Int32 i, Int32 j)

Two-parameter constructor found.

Constructing MyClass(int, int).

Values are x: 10, y: 20

Invoking methods on reflectOb.

sum is 30

14 is between x and y

Inside Set(int, int). Values are x: 9, y: 18

Inside Set(double, double). Values are x: 1, y: 23

Values are x: 1, y: 23

Let’s look at how reflection is used to construct a 

MyClass

 object. First, a list of the 

public constructors is obtained using the following statement:

ConstructorInfo[] ci = t.GetConstructors();

Next, for the sake of illustration, the constructors are displayed. Then the list is searched 

for a constructor that takes two arguments, using this code:

for(x=0; x < ci.Length; x++) {

  ParameterInfo[] pi =  ci[x].GetParameters();

  if(pi.Length == 2) break;

}

If the constructor is found (as it will be in this case), an object is instantiated by the 



following sequence:

// Construct the object.

object[] consargs = new object[2];

consargs[0] = 10;

consargs[1] = 20;

object reflectOb = ci[x].Invoke(consargs);

After the call to 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   590   591   592   593   594   595   596   597   ...   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