zoukankan      html  css  js  c++  java
  • List 高效转成 Datatable

     public static DataTable ToDataTable<T>(this IList<T> data)
            {
                PropertyDescriptorCollection props =
                    TypeDescriptor.GetProperties(typeof(T));
                DataTable table = new DataTable();
                for (int i = 0; i < props.Count; i++)
                {
                    PropertyDescriptor prop = props[i];
                    table.Columns.Add(prop.Name, prop.PropertyType);
                }
                object[] values = new object[props.Count];
                foreach (T item in data)
                {
                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = props[i].GetValue(item);
                    }
                    table.Rows.Add(values);
                }
                return table;
            }
  • 相关阅读:
    Laravel 出现 No application encryption key has been specified.
    windows下用composer局部安装laravel
    vue组件--通讯录
    vue组件--TagsInput
    axios封装(二)队列管理
    axios封装(一)基础配置
    [git hooks] pre-commit 配置
    qs.js
    flexbox的应用
    盒子模型详解
  • 原文地址:https://www.cnblogs.com/rhythmK/p/2490420.html
Copyright © 2011-2022 走看看