2017-01-23 22 views
-5

は私にグループ日付<辞書<文字列、文字列>>

List<Dictionary<string, string>> 

を返す最初の要素はフィールドであり、2番目は値です。特定の場合には

は、このリストは次の値があります。

{ datetime, '01/23/2017 01:10:30' } 
{ datetime, '01/23/2017 10:00:00' } 
{ datetime, '01/23/2017 11:23:15' } 
{ datetime, '01/20/2017 07:13:20' } 
{ datetime, '01/20/2017 08:20:11' } 
{ datetime, '01/21/2017 07:28:29' } 

私はこれを変換する必要があります。

{ '01/23/2017', { '01/23/2017 01:10:30', ''01/23/2017 10:00:00', '01/23/2017 11:23:15' } } 
{ '01/20/2017', { '01/20/2017 07:13:20', '01/20/2017 08:20:11' } } 
{ '01/21/2017', { '01/21/2017 07:28:29' } } 

はどのように進むのか?

+0

'datetime'は関係ありません、正しいですか? – Tatranskymedved

+0

これは、クエリによって返されたフィールドの名前だけです。 – msmosso

+0

あなたのデータベースからの応答は奇妙に思えます...なぜ辞書のリスト? – pimbrouwers

答えて

3

提供したデータに基づいて、これを行う方法が1つあります。このコードは書かれてLinqPadで実行し、その.Dump()しかない作品であることを、注意してください。

var source = new List<KeyValuePair<string, string>> { 
    new KeyValuePair<string, string>("datetime", "01/23/2017 01:10:30") , 
    new KeyValuePair<string, string>("datetime", "01/23/2017 10:00:00"), 
    new KeyValuePair<string, string>("datetime", "01/23/2017 11:23:15"), 
    new KeyValuePair<string, string>("datetime", "01/20/2017 07:13:20"), 
    new KeyValuePair<string, string>("datetime", "01/20/2017 08:20:11"), 
    new KeyValuePair<string, string>("datetime", "01/21/2017 07:28:29") 
}; 

var list = source.Select (s => s.Value) 
    .GroupBy (s => DateTime.ParseExact(s, "MM/dd/yyyy hh:mm:ss", CultureInfo.InvariantCulture).Date) 
    .ToList(); 

list.Dump(); 

出力:

enter image description here

関連する問題