OrderedDictionary.Item[] 속성

정의

지정한 값을 가져오거나 설정합니다.

오버로드

Item[Int32]

지정한 인덱스에 있는 값을 가져오거나 설정합니다.

Item[Object]

지정한 키가 있는 값을 가져오거나 설정합니다.

Item[Int32]

Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs

지정한 인덱스에 있는 값을 가져오거나 설정합니다.

public:
 property System::Object ^ default[int] { System::Object ^ get(int index); void set(int index, System::Object ^ value); };
public object this[int index] { get; set; }
public object? this[int index] { get; set; }
member this.Item(int) : obj with get, set
Default Public Property Item(index As Integer) As Object

매개 변수

index
Int32

가져오거나 설정할 값의 0부터 시작하는 인덱스입니다.

속성 값

지정한 인덱스에 있는 항목의 값입니다.

구현

예외

속성이 설정되어 있으며 OrderedDictionary 컬렉션이 읽기 전용인 경우

index가 0보다 작은 경우

또는

indexCount보다 크거나 같은 경우

설명

이 속성을 사용하면 구문을 myCollection[index]사용하여 컬렉션의 특정 요소에 액세스할 수 있습니다.

C# 언어는 키워드(keyword) 사용하여 속성을 구현하는 대신 인덱서를 정의합니다Item[]. Visual Basic은 Item[] 동일한 인덱싱 기능을 제공하는 기본 속성으로 구현됩니다.

적용 대상

Item[Object]

Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs
Source:
OrderedDictionary.cs

지정한 키가 있는 값을 가져오거나 설정합니다.

public:
 property System::Object ^ default[System::Object ^] { System::Object ^ get(System::Object ^ key); void set(System::Object ^ key, System::Object ^ value); };
public object this[object key] { get; set; }
public object? this[object key] { get; set; }
member this.Item(obj) : obj with get, set
Default Public Property Item(key As Object) As Object

매개 변수

key
Object

가져오거나 설정할 값의 키입니다.

속성 값

지정한 키와 연결된 값입니다. 지정한 키가 없는 경우 해당 키를 가져오려고 시도하면 null이 반환되고 해당 키를 설정하려고 시도하면 지정한 키를 사용하여 새 요소가 만들어집니다.

구현

예외

속성이 설정되어 있으며 OrderedDictionary 컬렉션이 읽기 전용인 경우

예제

다음 코드 예제에서는 컬렉션의 수정을 보여 줍니다 OrderedDictionary . 이 예제 Item[] 에서 속성은 키를 "testKey2"사용하여 사전 항목을 수정하는 데 사용됩니다. 이 코드는 에서 OrderedDictionary볼 수 있는 더 큰 코드 예제의 일부입니다.

// Modifying the OrderedDictionary
if (!myOrderedDictionary->IsReadOnly)
{
    // Insert a new key to the beginning of the OrderedDictionary
    myOrderedDictionary->Insert(0, "insertedKey1", "insertedValue1");

    // Modify the value of the entry with the key "testKey2"
    myOrderedDictionary["testKey2"] = "modifiedValue";

    // Remove the last entry from the OrderedDictionary: "testKey3"
    myOrderedDictionary->RemoveAt(myOrderedDictionary->Count - 1);

    // Remove the "keyToDelete" entry, if it exists
    if (myOrderedDictionary->Contains("keyToDelete"))
    {
        myOrderedDictionary->Remove("keyToDelete");
    }
}
// Modifying the OrderedDictionary
if (!myOrderedDictionary.IsReadOnly)
{
    // Insert a new key to the beginning of the OrderedDictionary
    myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1");

    // Modify the value of the entry with the key "testKey2"
    myOrderedDictionary["testKey2"] = "modifiedValue";

    // Remove the last entry from the OrderedDictionary: "testKey3"
    myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1);

    // Remove the "keyToDelete" entry, if it exists
    if (myOrderedDictionary.Contains("keyToDelete"))
    {
        myOrderedDictionary.Remove("keyToDelete");
    }
}
' Modifying the OrderedDictionary
If Not myOrderedDictionary.IsReadOnly Then

    ' Insert a new key to the beginning of the OrderedDictionary
    myOrderedDictionary.Insert(0, "insertedKey1", "insertedValue1")

    ' Modify the value of the entry with the key "testKey2"
    myOrderedDictionary("testKey2") = "modifiedValue"

    ' Remove the last entry from the OrderedDictionary: "testKey3"
    myOrderedDictionary.RemoveAt(myOrderedDictionary.Count - 1)

    ' Remove the "keyToDelete" entry, if it exists
    If (myOrderedDictionary.Contains("keyToDelete")) Then
        myOrderedDictionary.Remove("keyToDelete")
    End If
End If

설명

이 속성을 사용하면 구문을 myCollection[key]사용하여 컬렉션의 특정 요소에 액세스할 수 있습니다.

컬렉션에 Item[] 없는 OrderedDictionary 키의 값(예 myCollection["myNonexistentKey"] = myValue: )을 설정하여 속성을 사용하여 새 요소를 추가할 수도 있습니다. 그러나 지정된 키가 에 OrderedDictionary이미 있는 경우 속성을 설정 Item[] 하면 이전 값이 덮어씁니다. 반면, 메서드는 Add 기존 요소를 수정하지 않습니다.

키는 일 수 없지만 null값은 일 수 있습니다. 지정된 키를 찾을 수 null 없으며 지정된 키의 null값이 이므로 반환되기 때문에 반환되는 키를 구분 null 하려면 메서드를 사용하여 Contains 키가 에 OrderedDictionary있는지 확인합니다.

적용 대상