Bewerken

Delen via


StringDictionary.Values Property

Definition

Gets a collection of values in the 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

Property Value

An ICollection that provides the values in the StringDictionary.

Examples

The following code example enumerates the elements of a StringDictionary.

#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;

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

        Console::WriteLine("VALUES");
        for each (String^ val in myCol->Values)
        {
            Console::WriteLine(val);
        }
    }
};

int main()
{
    SamplesStringDictionary::Main();
}
// This code produces the following output.
// VALUES
// verde
// rojo
// azul
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

Remarks

The order of the values in the ICollection is unspecified, but it is the same order as the associated keys in the ICollection returned by the Keys method.

The returned ICollection is not a static copy; instead, the ICollection refers back to the values in the original StringDictionary. Therefore, changes to the StringDictionary continue to be reflected in the ICollection.

Retrieving the value of this property is an O(1) operation.

Applies to