OrderedDictionary.Item[] 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 값을 가져오거나 설정합니다.
오버로드
| Name | Description |
|---|---|
| Item[Int32] |
지정된 인덱스에서 값을 가져오거나 설정합니다. |
| Item[Object] |
지정된 키를 가진 값을 가져오거나 설정합니다. |
Item[Int32]
지정된 인덱스에서 값을 가져오거나 설정합니다.
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; }
member this.Item(int) : obj with get, set
Default Public Property Item(index As Integer) As Object
매개 변수
- index
- Int32
가져오기 또는 설정할 값의 인덱스(0부터 시작)입니다.
속성 값
지정된 인덱스의 항목 값입니다.
구현
예외
속성이 설정되고 컬렉션이 OrderedDictionary 읽기 전용입니다.
설명
이 속성을 사용하면 다음 구문을 myCollection[index]사용하여 컬렉션의 특정 요소에 액세스할 수 있습니다.
C# 언어는 이 키워드를 사용하여 속성을 구현하는 대신 인덱서를 정의합니다 Item[] . Visual Basic 동일한 인덱싱 기능을 제공하는 Item[]default 속성 구현합니다.
적용 대상
Item[Object]
지정된 키를 가진 값을 가져오거나 설정합니다.
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; }
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 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확인합니다.