C# 0 The Complete Reference


PART II C h a p t e r   2 1



Download 4,07 Mb.
Pdf ko'rish
bet807/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   803   804   805   806   807   808   809   810   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART II

C h a p t e r   2 1 :  

E x p l o r i n g   t h e   S y s t e m   N a m e s p a c e    

651


      Console.Write(i + " ");

    Console.WriteLine();

  }

}

The output is shown here:



Original order: 1 2 3 4 5

Reversed order: 5 4 3 2 1

Range reversed: 5 2 3 4 1

Copying an Array

Copying all or part of one array to another is another common array operation. To copy an 

array, use 

Copy( )

.

Copy( )

 can put elements at the start of the destination array or in the 

middle, depending upon which version of 



Copy( )

 you use. 



Copy( )

 is demonstrated by the 

following program:

// Copy an array.

using System;

class CopyDemo {

  static void Main() {

    int[] source = { 1, 2, 3, 4, 5 };

    int[] target = { 11, 12, 13, 14, 15 };

    int[] source2 = { -1, -2, -3, -4, -5 };

    // Display source.

    Console.Write("source: ");

    foreach(int i in source)

      Console.Write(i + " ");

    Console.WriteLine();

    // Display original target.

    Console.Write("Original contents of target: ");

    foreach(int i in target)

      Console.Write(i + " ");

    Console.WriteLine();

    // Copy the entire array.

    Array.Copy(source, target, source.Length);

    // Display copy.

    Console.Write("target after copy:  ");

    foreach(int i in target)

      Console.Write(i + " ");

    Console.WriteLine();

    // Copy into middle of target.

    Array.Copy(source2, 2, target, 3, 2);

    // Display copy.

    Console.Write("target after copy:  ");

    foreach(int i in target)

www.freepdf-books.com



652

 

P a r t   I I :  



E x p l o r i n g   t h e   C #   L i b r a r y

      Console.Write(i + " ");

    Console.WriteLine();

  }


}

The output is shown here:

source: 1 2 3 4 5

Original contents of target: 11 12 13 14 15

target after copy:  1 2 3 4 5

target after copy:  1 2 3 -3 -4




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   803   804   805   806   807   808   809   810   ...   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