SortedList.CopyTo copies SortedList elements to a one-dimensional Array object : SortedList « Collections Data Structure « C# / C Sharp






SortedList.CopyTo copies SortedList elements to a one-dimensional Array object

  
 using System;
 using System.Collections;
 public class SamplesSortedList  {
    public static void Main()  {
       SortedList mySourceList = new SortedList();
       mySourceList.Add( 2, "A" );
       mySourceList.Add( 3, "B" );
       mySourceList.Add( 1, "C" );

       String[] tempArray = new String[] { "This", "is", "a", "test" };
       DictionaryEntry[] myTargetArray = new DictionaryEntry[15];
       int i = 0;
       foreach ( String s in tempArray )  {
          myTargetArray[i].Key = i;
          myTargetArray[i].Value = s;
          i++;
       }
       mySourceList.CopyTo( myTargetArray, 6 );
       PrintValues( myTargetArray, ' ' );
    }

    public static void PrintValues( DictionaryEntry[] myArr, char mySeparator )  {
       for ( int i = 0; i < myArr.Length; i++ )
          Console.Write( "{0}{1}", mySeparator, myArr[i].Value );
       Console.WriteLine();
    }

 }

   
    
  








Related examples in the same category

1.Create SortedList sorted according to the specified IComparer
2.Create a SortedList using case-insensitive comparer
3.Create a SortedList using CaseInsensitiveComparer based on the Turkish culture (tr-TR)
4.Create a SortedList using the StringComparer.InvariantCultureIgnoreCase value.
5.SortedList is a collection of key/value pairs that are sorted by the keys and are accessible by key and by index.
6.SortedList.Add Method Adds an element with key and value to a SortedList object.
7.SortedList.Clear removes all elements from a SortedList object.
8.SortedList.Contains Determines whether a SortedList object contains a specific key.
9.SortedList.GetByIndex gets the value at the specified index of a SortedList object.
10.SortedList.IndexOfKey returns the zero-based index of the specified key in a SortedList object.
11.SortedList.IsSynchronized tells whether access to a SortedList object is synchronized (thread safe).
12.SortedList.Remove removes the element with the specified key from a SortedList object.
13.SortedList.SetByIndex replaces the value at a specific index in a SortedList object.
14.Add element to SortedListAdd element to SortedList
15.Add to SortedList, get by key and index
16.Delete element in a SortedList with RemoveAt
17.illustrates the use of a SortedListillustrates the use of a SortedList
18.illustrates the use of the SortedList methodsillustrates the use of the SortedList methods
19.Demonstrate a SortedListDemonstrate a SortedList
20.Create a SortedList using the default comparer
21.Create a SortedList using the specified case-insensitive comparer
22.Create a SortedList using the specified CaseInsensitiveComparer
23.Parametr Collection