2
Answers

NP99 CopyTo()

Maha

Maha

16y
2.2k
1

Hi Guys

 

NP98 CopyTo()

 

In the following program list.CopyTo(array1); is producing same result as list.CopyTo(array1, 0);.

 

Please explain the reason.

 

Thank you

 

using System;

using System.Collections;

 

class MainClass

{

   public static void Main(string[] args)

   {

      // Create a new ArrayList and populate it.

      ArrayList list = new ArrayList(5);

      list.Add("B");

      list.Add("G");

      list.Add("J");

      list.Add("S");

      list.Add("M");

 

      string[] array1 = new string[list.Count];

 

      list.CopyTo(array1, 0);

 

      Console.WriteLine("Array 1:");

 

      foreach (string s in array1)

      {

         Console.WriteLine("\t{0}", s);

      }

   }

}

/*

Array 1:

        B

        G

        J

        S

        M

*/

Answers (2)