最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

c#將list類型轉(zhuǎn)換成DataTable方法示例

 更新時(shí)間:2013年12月26日 09:51:36   作者:  
將List類型轉(zhuǎn)換成DataTable的通用方法,大家參考使用吧

復(fù)制代碼 代碼如下:

/// <summary>
       /// 將List轉(zhuǎn)換成DataTable
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <param name="data"></param>
       /// <returns></returns>
       public static DataTable ToDataTable<T>(this IList<T> data)
           {
           PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));
           DataTable dt = new DataTable();
           for (int i = 0; i < properties.Count; i++)
               {
               PropertyDescriptor property = properties[i];
               dt.Columns.Add(property.Name, property.PropertyType);
               }
           object[] values = new object[properties.Count];
           foreach (T item in data)
               {
               for (int i = 0; i < values.Length; i++)
                   {
                   values[i] = properties[i].GetValue(item);
                   }
               dt.Rows.Add(values);
               }
           return dt;
           }

相關(guān)文章

最新評(píng)論

辰溪县| 清涧县| 浦江县| 沁水县| 嘉祥县| 沈阳市| 从江县| 怀来县| 扶绥县| 龙陵县| 隆昌县| 彭山县| 新安县| 兴城市| 禄劝| 长寿区| 江华| 中阳县| 舞钢市| 青河县| 静海县| 高雄市| 徐闻县| 收藏| 沂源县| 屏边| 香河县| 依安县| 府谷县| 正镶白旗| 神池县| 乳山市| 麻阳| 宁津县| 眉山市| 上思县| 马鞍山市| 凤城市| 河津市| 大厂| 达孜县|