C# Language Specification


Nested types in generic classes



Download 0,75 Mb.
bet349/524
Sana06.01.2022
Hajmi0,75 Mb.
#324842
1   ...   345   346   347   348   349   350   351   352   ...   524
Bog'liq
CSharp Language Specification

Nested types in generic classes


A generic class declaration can contain nested type declarations. The type parameters of the enclosing class can be used within the nested types. A nested type declaration can contain additional type parameters that apply only to the nested type.

Every type declaration contained within a generic class declaration is implicitly a generic type declaration. When writing a reference to a type nested within a generic type, the containing constructed type, including its type arguments, must be named. However, from within the outer class, the nested type can be used without qualification; the instance type of the outer class can be implicitly used when constructing the nested type. The following example shows three different correct ways to refer to a constructed type created from Inner; the first two are equivalent:

class Outer
{
class Inner
{
public static void F(T t, U u) {...}
}

static void F(T t) {


Outer.Inner.F(t, "abc"); // These two statements have
Inner.F(t, "abc"); // the same effect

Outer.Inner.F(3, "abc"); // This type is different

Outer.Inner.F(t, "abc"); // Error, Outer needs type arg
}
}

Although it is bad programming style, a type parameter in a nested type can hide a member or type parameter declared in the outer type:

class Outer
{
class Inner // Valid, hides Outer’s T
{
public T t; // Refers to Inner’s T
}
}


      1. Download 0,75 Mb.

        Do'stlaringiz bilan baham:
1   ...   345   346   347   348   349   350   351   352   ...   524




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