C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet209/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   205   206   207   208   209   210   211   212   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

jagged[0]

 a reference to a 4×2 array:

jagged[0] = new int[4, 2];

The following statement assigns a value to 



jagged[0][1,0]

:

jagged[0][1,0] = i;



Assigning Array References

As with other objects, when you assign one array reference variable to another, you are 

simply making both variables refer to the same array. You are neither causing a copy of the 

www.freepdf-books.com




PART I

C h a p t e r   7 :  

A r r a y s   a n d   S t r i n g s  

147


PART IPART I

array to be created, nor are you causing the contents of one array to be copied to the other. 

For example, consider this program:

// Assigning array reference variables.

using System;

class AssignARef {

  static void Main() {

    int i;

    int[] nums1 = new int[10];

    int[] nums2 = new int[10];

    for(i=0; i < 10; i++) nums1[i] = i;

    for(i=0; i < 10; i++) nums2[i] = -i;

    Console.Write("Here is nums1: ");

    for(i=0; i < 10; i++)

      Console.Write(nums1[i] + " ");

    Console.WriteLine();

    Console.Write("Here is nums2: ");

    for(i=0; i < 10; i++)

      Console.Write(nums2[i] + " ");

    Console.WriteLine();

    nums2 = nums1; // now nums2 refers to nums1

    Console.Write("Here is nums2 after assignment: ");

    for(i=0; i < 10; i++)

      Console.Write(nums2[i] + " ");

    Console.WriteLine();

    // Next, operate on nums1 array through nums2.

    nums2[3] = 99;

    Console.Write("Here is nums1 after change through nums2: ");

    for(i=0; i < 10; i++)

      Console.Write(nums1[i] + " ");

    Console.WriteLine();

  }


}

The output from the program is shown here:

Here is nums1: 0 1 2 3 4 5 6 7 8 9

Here is nums2: 0 -1 -2 -3 -4 -5 -6 -7 -8 -9

Here is nums2 after assignment: 0 1 2 3 4 5 6 7 8 9

Here is nums1 after change through nums2: 0 1 2 99 4 5 6 7 8 9

As the output shows, after the assignment of 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   205   206   207   208   209   210   211   212   ...   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