StringDictionary.Values Egenskap

Definition

Hämtar en samling värden i StringDictionary.

public:
 virtual property System::Collections::ICollection ^ Values { System::Collections::ICollection ^ get(); };
public virtual System.Collections.ICollection Values { get; }
member this.Values : System.Collections.ICollection
Public Overridable ReadOnly Property Values As ICollection

Egenskapsvärde

En ICollection som innehåller värdena i StringDictionary.

Exempel

I följande kodexempel räknas elementen i en StringDictionary.

using System;
using System.Collections;
using System.Collections.Specialized;

public class SamplesStringDictionary
{
    public static void Main()
    {
        // Creates and initializes a new StringDictionary.
        StringDictionary myCol = new StringDictionary();
        myCol.Add( "red", "rojo" );
        myCol.Add( "green", "verde" );
        myCol.Add( "blue", "azul" );

        Console.WriteLine("VALUES");
        foreach (string val in myCol.Values)
        {
            Console.WriteLine(val);
        }
    }
}
// This code produces the following output.
// VALUES
// verde
// rojo
// azul
Imports System.Collections
Imports System.Collections.Specialized

Public Class SamplesStringDictionary
    Public Shared Sub Main()
        ' Creates and initializes a new StringDictionary.
        Dim myCol As New StringDictionary()
        myCol.Add( "red", "rojo" )
        myCol.Add( "green", "verde" )
        myCol.Add( "blue", "azul" )

        Console.WriteLine("VALUES")
        For Each val As String In myCol.Values
            Console.WriteLine(val)
        Next val
    End Sub
End Class

' This code produces the following output.
'
' VALUES
' verde
' rojo
' azul

Kommentarer

Ordningen på värdena i ICollection är ospecificerad, men det är samma ordning som de associerade nycklarna i den ICollection som returneras av Keys metoden.

Den returnerade ICollection är inte en statisk kopia. I stället ICollection refererar den tillbaka till värdena i den ursprungliga StringDictionary. Därför fortsätter ändringarna att StringDictionary återspeglas i ICollection.

Att hämta värdet för den här egenskapen är en O(1)-åtgärd.

Gäller för