Dictionary c#字典到数据表

Dictionary c#字典到数据表,dictionary,datatable,Dictionary,Datatable,我有这本字典: KEY VALUE 08/10/2013, 00:00:00, a, b​​, c, d, e, f, g, h, i 08/10/2013, 00:01:00, a, b​​, c, d, e, f, g, h, i 08/10/2013, 00:02:00, a, b​​, c, d, e, f, g, h, i 08/10/2013, 00:03:00, a, b​​, c, d, e, f, g, h, i 08/10/2013, 00

我有这本字典:

KEY                   VALUE
08/10/2013, 00:00:00, a, b​​, c, d, e, f, g, h, i
08/10/2013, 00:01:00, a, b​​, c, d, e, f, g, h, i
08/10/2013, 00:02:00, a, b​​, c, d, e, f, g, h, i
08/10/2013, 00:03:00, a, b​​, c, d, e, f, g, h, i
08/10/2013, 00:04:00, a, b​​, c, d, e, f, g, h, i
08/10/2013, 00:05:00, a, b​​, c, d, e, f, g, h, i
08/10/2013, 00:06:00, a, b​​, c, d, e, f, g, h, i
日期和时间是我的钥匙,而a,b​​, c、 d,e,f,g,h,i’是我的价值观​​.

我想把上面的字典放在
数据表中

我该怎么做? 使用两个
foreach
循环

private static void DictonaryTodataTable (DataTable dtResult, Dictionary <DateTime, CommaSeparatedList> CSVData)
{
    foreach (KeyValuePair item in <DateTime, CommaSeparatedList> CSVData)
    {
        DtResult.NewRow DataRow dr = ();
        
        [ CODE ]
        dtResult.Rows.Add (dr);
    }
}
private static void dictonarytodata(数据表dtResult,字典CSVData)
{
foreach(CSVData中的KeyValuePair项)
{
DtResult.NewRow DataRow dr=();
    
[守则]
dtResult.Rows.Add(dr);
}
}

数据行可以保存列的索引值或散列值。您可以使用dr[0]、dr[1]。。。或dr[“columnA”]、dr[“columnB”]

假设CommaSeparatedList可以迭代字符串,您可以用它替换[CODE],尽管您可能需要强制转换或其他方法来处理从逗号分隔列表中提取字符串

int count = 0;
dr[count++] = item.Key; // You could cast this to a string and/or format it here...
foreach(string column in item.Value){ dr[count++]=column; }

您所拥有的看起来还可以-是什么阻止了它的工作?如何在字典中插入数据表?我想有:时间戳-第1列-第2列-第3列-列。。。2013年10月8日,00:00:00,a b c d等。。如何在foreach内部进行?很好,但如何使铸件仅成为第一个元素?它必须是一个时间戳。谢谢你,你不需要。。这只是一个建议,完全取决于你的需要。可以将该列指定为DateTime对象。DataRow ItemArray接受一个对象[],因此您可以传递任何需要的内容。可以一次将整个数组指定给行或列。都在文件里。。。然后,我查看了文档,我的字典有一个头,我想从当前字典中删除,但以后再使用它。我该怎么办?非常感谢。