C# 0 The Complete Reference



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

GetConstructors( )

 on a 


Type

 object. One 

commonly used form is shown here:

ConstructorInfo[ ] GetConstructors( )

It returns an array of 

ConstructorInfo

 objects that describe the constructors.



ConstructorInfo

 is derived from the abstract class 



MethodBase

, which inherits 



MemberInfo

. It also defines several members of its own. The one we are interested in is 



GetParameters( )

, which returns a list of the parameters associated with a constructor. It 

works just like 

GetParameters( )

 defined by 



MethodInfo

, described earlier.

Once an appropriate constructor has been found, an object is created by calling the 

Invoke( )

 method defined by 



ConstructorInfo

. One form is shown here:

object Invoke(object[ ] 

args

)

Any arguments that need to be passed to the method are specified in the array 



args.

 If no 


arguments are needed, pass 

null

 to 


args.

 In all cases, 



args

 must contain exactly the same 

number of elements as there are arguments and the types of arguments must be compatible 

with the types of the parameters. 



Invoke( )

 returns a reference to the object that was 

constructed.

The following program uses reflection to create an instance of 



MyClass

:

// Create an object using reflection.



using System;

using System.Reflection;

class MyClass {

  int x;


  int y;

  public MyClass(int i) {

    Console.WriteLine("Constructing MyClass(int, int). ");

    x = y = i;

  }

  public MyClass(int i, int j) {



    Console.WriteLine("Constructing MyClass(int, int). ");

    x = i;

    y = j;

    Show();

  }

  public int Sum() {



    return x+y;

  }


  public bool IsBetween(int i) {

    if((x < i) && (i < y)) return true;

    else return false;

  }


  public void Set(int a, int b) {

    Console.Write("Inside Set(int, int). ");

www.freepdf-books.com



Download 4,07 Mb.

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