cipher = new Dictionary<char,int>;
cipher.Add( 'a', 324 );
cipher.Add( 'b', 553 );
cipher.Add( 'c', 915 );
How to get the 2nd 요소점? 예를 들어, 다음과 같은 항목을 같은 I& # 39; d
KeyValuePair pair = cipher[1]
여기서 페어당 map_layer (& # 39, b& # 39, 553) ''
List<KeyValuePair<char, int>> cipher = new List<KeyValuePair<char, int>>();
cipher.Add( new KeyValuePair<char, int>( 'a', 324 ) );
cipher.Add( new KeyValuePair<char, int>( 'b', 553 ) );
cipher.Add( new KeyValuePair<char, int>( 'c', 915 ) );
KeyValuePair<char, int> pair = cipher[ 1 ];
정작 필요한 키를 통해 조회할 수 있습니까? 그렇지 않으면,, ',' List< 사용하여 KeyValuePair< 챨 int> > (또는 그 이상 아직이라구요 만드시겠습니까 유형을 캡슐화합니다 챨 및 정수).
T - 가 구현할 수 있는 사전 aren& # 39, 본질적으로 정렬할지 사전에 .NET 에서는 주요 가 아닌 오더할 삽입에서 정렬할지 정렬됩니다.
필요한 경우, d # 39 에서 모두 취합은 액세스하려면 삽입에서 I& 추천합니까 목록 및 사전 주문 및 키를 캡슐화 단일 취합은 유형:.
대신에, 만약 이 목록은 매우 짧은 선형 검색, 조회 수행여 놈팽이한테 인덱스화할 의해 허용하시겠습니까 될 것입니다.
엘레멘테 () '이' 처럼 사용할 수 있습니다.
cipher.ElementAt(index);
그 때문에 이 방식에 비해 '보다' 옵션을 통해 선택할 수 없는 don& # 39, 루프 사전:
/// <summary>Returns the element at a specified index in a sequence.</summary>
/// <returns>The element at the specified position in the source sequence.</returns>
/// <param name="source">An <see cref="T:System.Collections.Generic.IEnumerable`1" /> to return an element from.</param>
/// <param name="index">The zero-based index of the element to retrieve.</param>
/// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="source" /> is null.</exception>
/// <exception cref="T:System.ArgumentOutOfRangeException">
/// <paramref name="index" /> is less than 0 or greater than or equal to the number of elements in <paramref name="source" />.</exception>
이 질문의 질문과대답 frequencyid 중복 제거 할 수 있었다. https://stackoverflow.com/questions/6384528/how-to-retrieve-nth-item-in-dictionary/6384552. 하지만 난 여기 실종된 사실을 알고 답을 해야 한다고 단힌 곧 새로운 러디어드리스티오나리 구분된다.
이제 (vmware. .NET 4), ui_policytable_java_spe_policy 러디어드리스티오나리 구분된다. 이렇게 하면 제공하면서 파르게 조회를 오더할. 항목 (Int32) 메서드로부터 되돌려줍니다 n 요소.
그냥 내가 던져진 데 급급한 기존 사양명세 위한 사전, 일부 코드와 지었지.
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("a", "apple");
d.Add("b", "ball");
d.Add("c", "cat");
d.Add("d", "dog");
int t = 0;
foreach (string s in d.Values)
{
t++;
if (t == 2) Console.WriteLine(s);
}
그리고 두 번째 항목을 않니다 쓸 것 (ball" ";) 콘솔 반복적으로. N 번째 요소 메서드를 호출할 경우, 그것은 아마도 랩된 it 를 얻을 수 있는 것이다. 이것은 아주 추악한 말입니다. # 39 로 대신 할 수 있다면, you& 스페인들리스트 @thecoop 제안됩니다; d 더 끄기입니다.
var cipher = new Dictionary<char, int>();
cipher.Add('a', 324);
cipher.Add('b', 553);
cipher.Add('c', 915);
var nThValue = cipher.Select((Val, Index) => new { Val, Index })
.Single(viPair => viPair.Index == 1) //Selecting dictionary item with it's index using index
.Val //Extracting KeyValuePair from dictionary item
.Value; //Extracting Value from KeyValuePair
이것은 오래된 질문, 그 당시 도움됐네 다는일은. # 39 의 구현 here& 제가 사용합니다. N 번째 요소에 따라 삽입에서 내가 원하는 건 등의 순이었다.
public class IndexedDictionary<TKey, TValue> : IEnumerable<TValue> {
private List<TValue> list = new List<TValue>();
private Dictionary<TKey, TValue> dict = new Dictionary<TKey, TValue>();
public TValue this[int index] { get { return list[index]; } }
public TValue this[TKey key] { get { return dict[key]; } }
public Dictionary<TKey, TValue>.KeyCollection Keys { get { return dict.Keys; } }
public int Count { get { return list.Count; } }
public int IndexOf(TValue item) { return list.IndexOf(item); }
public int IndexOfKey(TKey key) { return list.IndexOf(dict[key]); }
public void Add(TKey key, TValue value) {
list.Add(value);
dict.Add(key, value);
}
IEnumerator<TValue> IEnumerable<TValue>.GetEnumerator() {
return list.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() {
return list.GetEnumerator();
}
}