2009-09-04 2 views
1

으로 나는 사전을 만들고 싶습니다>, List<DateTime>사전 <TValue

나는이 어떻게 할 수있는 a를 TKEY은 문자열이며, TValue은?

덕분에 새 항목을 추가 할 때, 당신은 값에 새 목록을 할당해야한다는

답변

10
Dictionary<string, List<DateTime>> dict = new Dictionary<string, List<DateTime>>(); 

참고 :

string key; // assuming that's your key 
List<DateTime> value; 
if (!dict.TryGetValue(key, out value)) { 
    value = new List<DateTime>(); 
    dict.Add(key, value); 
} 
// value is now always a valid instance 
+1

+1 : 나는 늦게 ... 이초이었다 O) –

+0

OOOOoooops ..... 나는 술에 취해 있습니까? .... 아마 내가 이걸 시도했지만 아마도 정확히이 것은 아니었다. :) 감사합니다 –

1
Dictionary<string, List<DateTime>> 
+0

아마 좀 더 구체적이어야합니다. –

2
var dict = new Dictionary<string, List<DateTime>>(); 

친절,

1
Dictionary<string, List<DateTime>> oDictionary; 
1

아마 같은 :

Dictionary<String, List<DateTime>> myDict = new Dictionary<String, List<DateTime>>(); 
관련 문제