日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

C#_List转换成DataTable

發布時間:2025/4/9 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#_List转换成DataTable 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/// <summary>/// 講list集合轉換成datatable/// </summary>/// <param name="list"></param>/// <returns></returns>public static System.Data.DataTable ListToDataTable(IList list){System.Data.DataTable result = new System.Data.DataTable();if (list.Count > 0){PropertyInfo[] propertys = list[0].GetType().GetProperties();foreach (PropertyInfo pi in propertys){//獲取類型Type colType = pi.PropertyType;//當類型為Nullable<>時if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>))){colType = colType.GetGenericArguments()[0];}result.Columns.Add(pi.Name, colType);}for (int i = 0; i < list.Count; i++){ArrayList tempList = new ArrayList();foreach (PropertyInfo pi in propertys){object obj = pi.GetValue(list[i], null);tempList.Add(obj);}object[] array = tempList.ToArray();result.LoadDataRow(array, true);}}return result;}

?

轉載于:https://www.cnblogs.com/ingstyle/p/4166392.html

總結

以上是生活随笔為你收集整理的C#_List转换成DataTable的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。