C# 0 The Complete Reference


MyClass , implements  IMyInterface



Download 4,07 Mb.
Pdf ko'rish
bet652/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   648   649   650   651   652   653   654   655   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

MyClass

, implements 



IMyInterface

, and has a parameterless constructor.

When using two or more type parameters, you can specify a constraint for each 

parameter by using a separate 



where

 clause. Here is an example:

// Use multiple where clauses.

using System;

// Gen has two type arguments and both have a where clause.

class Gen where T : class

                where V : struct {

  T ob1;


  V ob2;

  public Gen(T t, V v) {

    ob1 = t;

    ob2 = v;

  }

}

class MultipleConstraintDemo {



  static void Main() {

    // This is OK because string is a class and

    // int is a value type.

    Gen obj = new Gen("test", 11);

    // The next line is wrong because bool is not

    // a reference type.

//    Gen obj = new Gen(true, 11);

  }


}

In this example, 



Gen

 takes two type arguments and both have a 



where

 clause. Pay 

special attention to its declaration:

class Gen where T : class

                where V : struct {

Notice the only thing that separates the first 



where

 clause from the second is whitespace. 

No other punctuation is required or valid.

www.freepdf-books.com




522

 

P a r t   I :  



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


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   648   649   650   651   652   653   654   655   ...   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