C# Language Specification



Download 0,75 Mb.
bet430/524
Sana06.01.2022
Hajmi0,75 Mb.
#324842
1   ...   426   427   428   429   430   431   432   433   ...   524
Bog'liq
CSharp Language Specification

The System.Array type


The type System.Array is the abstract base type of all array types. An implicit reference conversion (§6.1.6) exists from any array type to System.Array, and an explicit reference conversion (§6.2.4) exists from System.Array to any array type. Note that System.Array is not itself an array-type. Rather, it is a class-type from which all array-types are derived.

At run-time, a value of type System.Array can be null or a reference to an instance of any array type.


      1. Arrays and the generic IList interface


A one-dimensional array T[] implements the interface System.Collections.Generic.IList (IList for short) and its base interfaces. Accordingly, there is an implicit conversion from T[] to IList and its base interfaces. In addition, if there is an implicit reference conversion from S to T then S[] implements IList and there is an implicit reference conversion from S[] to IList and its base interfaces (§6.1.6). If there is an explicit reference conversion from S to T then there is an explicit reference conversion from S[] to IList and its base interfaces (§6.2.4). For example:

using System.Collections.Generic;

class Test
{
static void Main() {
string[] sa = new string[5];
object[] oa1 = new object[5];
object[] oa2 = sa;

IList lst1 = sa; // Ok


IList lst2 = oa1; // Error, cast needed
IList lst3 = sa; // Ok
IList lst4 = oa1; // Ok

IList lst5 = (IList)oa1; // Exception


IList lst6 = (IList)oa2; // Ok
}
}

The assignment lst2 = oa1 generates a compile-time error since the conversion from object[] to IList is an explicit conversion, not implicit. The cast (IList)oa1 will cause an exception to be thrown at run-time since oa1 references an object[] and not a string[]. However the cast (IList)oa2 will not cause an exception to be thrown since oa2 references a string[].

Whenever there is an implicit or explicit reference conversion from S[] to IList, there is also an explicit reference conversion from IList and its base interfaces to S[] (§6.2.4).

When an array type S[] implements IList, some of the members of the implemented interface may throw exceptions. The precise behavior of the implementation of the interface is beyond the scope of this specification.



Download 0,75 Mb.

Do'stlaringiz bilan baham:
1   ...   426   427   428   429   430   431   432   433   ...   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