C# DataTable,通过行/列索引获取值

标签 c# indexing data-structures datatable

这个问题在这里已经有了答案:





Get Cell Value from a DataTable in C#

(6 个回答)


4年前关闭。




我有一个 DataTable它由一个 csv 文件填充,有 8 列和大约 2000 行。我希望使用当前存储在我的 DataTable 中的 csv 值填充对象

如何索引特定的 DataTable细胞?换句话说,我希望以与处理 2D 数组类似的方式处理数据表,如下所示:
string value = array[i][j];
这是我的代码:

DataTable d = GetDataTableFromCSVFile(file);
for (int i = 0; i < d.Rows.Count; i++)
{
    for (int j = 0; j < d.Columns.Count; j++)
    {
         //string x = d[i][j]; <-- something like this.
    }
} 

最佳答案

像这样

string x = d.Rows[i][j].ToString()

关于C# DataTable,通过行/列索引获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45428041/

相关文章:

c# - 在堆栈中查找最长的字符序列

algorithm - 动态加载骰子的数据结构?

c# - 使用正则表达式按类名选择 xml 元素

r - 获取向量的最后 n 个元素。有没有比使用 length() 函数更好的方法?

sql - SQL Server 2008 中的索引 View

list - 索引嵌套列表/环境的有效(或最有效)方法是什么?

python - 用于在内存中维护表格数据的数据结构?

data-structures - 链表的应用

c# - Parallel.For与ThreadPool和异步/等待

c# - 如何向 DataGrid 添加行和列?