Export (0) Print
Expand All

SortedList.GetValueList Method

Gets the values in a SortedList object.

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)

public virtual IList GetValueList ()
public IList GetValueList ()
public function GetValueList () : IList
Not applicable.

Return Value

An IList object containing the values in the SortedList object.

The returned IList object is a read-only view of the values of the SortedList object. Modifications made to the underlying SortedList are immediately reflected in the IList.

The elements of the returned IList are sorted in the same order as the values of the SortedList.

This method is similar to the Values property, but returns an IList object instead of an ICollection object.

This method is an O(1) operation.

The following code example shows how to get one or all the keys or values in a SortedList object.

using System;
using System.Collections;
public class SamplesSortedList  {

   public static void Main()  {

      // Creates and initializes a new SortedList.
      SortedList mySL = new SortedList();
      mySL.Add( 1.3, "fox" );
      mySL.Add( 1.4, "jumped" );
      mySL.Add( 1.5, "over" );
      mySL.Add( 1.2, "brown" );
      mySL.Add( 1.1, "quick" );
      mySL.Add( 1.0, "The" );
      mySL.Add( 1.6, "the" );
      mySL.Add( 1.8, "dog" );
      mySL.Add( 1.7, "lazy" );

      // Gets the key and the value based on the index.
      int myIndex=3;
      Console.WriteLine( "The key   at index {0} is {1}.", myIndex, mySL.GetKey( myIndex ) );
      Console.WriteLine( "The value at index {0} is {1}.", myIndex, mySL.GetByIndex( myIndex ) );

      // Gets the list of keys and the list of values.
      IList myKeyList = mySL.GetKeyList();
      IList myValueList = mySL.GetValueList();

      // Prints the keys in the first column and the values in the second column.
      Console.WriteLine( "\t-KEY-\t-VALUE-" );
      for ( int i = 0; i < mySL.Count; i++ )
         Console.WriteLine( "\t{0}\t{1}", myKeyList[i], myValueList[i] );
   }
}
/* 
This code produces the following output.

The key   at index 3 is 1.3.
The value at index 3 is fox.
    -KEY-    -VALUE-
    1    The
    1.1    quick
    1.2    brown
    1.3    fox
    1.4    jumped
    1.5    over
    1.6    the
    1.7    lazy
    1.8    dog
*/ 

import System.*;
import System.Collections.*;

public class SamplesSortedList
{
    public static void main(String[] args)
    {
        // Creates and initializes a new SortedList.
        SortedList mySL = new SortedList();

        mySL.Add((System.Single)1.3, "fox");
        mySL.Add((System.Single)1.4, "jumped");
        mySL.Add((System.Single)1.5, "over");
        mySL.Add((System.Single)1.2, "brown");
        mySL.Add((System.Single)1.1, "quick");
        mySL.Add((System.Single)1.0, "The");
        mySL.Add((System.Single)1.6, "the");
        mySL.Add((System.Single)1.8, "dog");
        mySL.Add((System.Single)1.7, "lazy");

        // Gets the key and the value based on the index.
        int myIndex = 3;

        Console.WriteLine("The key   at index {0} is {1}.", 
            System.Convert.ToString(myIndex), mySL.GetKey(myIndex));
        Console.WriteLine("The value at index {0} is {1}.", 
            System.Convert.ToString(myIndex), mySL.GetByIndex(myIndex));

        // Gets the list of keys and the list of values.
        IList myKeyList = mySL.GetKeyList();
        IList myValueList = mySL.GetValueList();

        // Prints the keys in the first column and the values in the 
        // second column.
        Console.WriteLine("\t-KEY-\t-VALUE-");
        for (int i = 0; i < mySL.get_Count(); i++) {
            Console.WriteLine("\t{0}\t{1}", myKeyList.get_Item(i), 
                myValueList.get_Item(i));
        }
    } //main
} //SamplesSortedList

/* 
 This code produces the following output.
 
 The key   at index 3 is 1.3.
 The value at index 3 is fox.
     -KEY-    -VALUE-
     1    The
     1.1    quick
     1.2    brown
     1.3    fox
     1.4    jumped
     1.5    over
     1.6    the
     1.7    lazy
     1.8    dog
 */

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft