这些方法实际上是做什么的? [英] What Does These Methods Actually Do?

查看:93
本文介绍了这些方法实际上是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static Dictionary<string, object> ToJson(DataTable table)
{
    Dictionary<string, object> j = new Dictionary<string, object>();
    j.Add(table.TableName, RowsToDictionary(table));
    return j;
}

private static List<Dictionary<string, object>> RowsToDictionary(DataTable table)
{
    List<Dictionary<string, object>> objs =
        new List<Dictionary<string, object>>();
    foreach (DataRow dr in table.Rows)
    {
        Dictionary<string, object> drow = new Dictionary<string, object>();
        for (int i = 0; i < table.Columns.Count; i++)
        {
            drow.Add(table.Columns[i].ColumnName, dr[i]);
        }
        objs.Add(drow);
    }

    return objs;
}

推荐答案

好吧,第二种方法RowsToDictionaryDataTable 转换为字典列表(基本上是将整个表转换为C#类似于表结构的数据结构),而第二种方法ToJson实际上为其命名并返回它
Well, the second method RowsToDictionary converts a DataTable to a List of Dictionaries (basically it translates a whole table into a C# data structure that resembles the structure of a table), while the second method ToJson actually gives it a name and returns it


这篇关于这些方法实际上是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆