【问题标题】:i need fast and convenient way to organize table data in-memory我需要快速方便的方法来组织内存中的表数据
【发布时间】:2011-03-27 04:28:15
【问题描述】:

初始条件:

DateTime moment

string key

double value

我想在代码中的某个地方

Add("2010.08.09 12:55:34", "px_ValX", 10);
Add("2010.08.09 12:55:35", "px_ValX", 1);
Add("2010.08.09 12:55:35", "px_ValY", 12);
Add("2010.08.09 12:55:35", "px_ValZ", 100);
Add("2010.08.09 12:55:38", "px_ValZ", 5); 

然后我想从该数据数组中获取表格

DataTable ToTable()

产生

date|px_valX|px_ValY|px_ValZ
"2010.08.09 12:55:34"|10|0|0
"2010.08.09 12:55:35"|1|12|100
"2010.08.09 12:55:38"|0|0|5

如果我能做得很快,那就太棒了

double Get(DateTime moment, string key)

DataTable Get(string key) 

生成下表

data|value
"2010.08.09 12:55:34"|10

这是相当 SQL 任务,但我需要内存数据结构。我打算使用 C# DataTable 类及其 Select 方法,但我认为有更快捷方便的方法。

此时此刻,我在我的应用程序中使用了以下类

[Serializable]
public class CalcItem
{
    public CalcItem()
    {
        Additional = new Dictionary<string, double>();
    }
    public Dictionary<string, double> Additional { get; set; }

    public DateTime Date { get; set; }
}

在 CalcItemManager 中

public List<CalcItem> CalcItems { get; set; }

我要添加数据

var clc = new CalcItem();
clc.Additional.Add("px_ValX", 10);
_dataManager.CalcItems.Add(clc);

【问题讨论】:

    标签: c# .net dictionary datatable hashtable


    【解决方案1】:
    猜你喜欢
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-29
    • 2012-04-05
    • 2019-07-29
    • 2019-05-23
    • 2016-02-12
    相关资源
    最近更新 更多