我有以下静态类来构建动态对象数组:
public class oDataArray
{
public static List<List<object>> GetDataObject(DbCommand command)
{
List<List<object>> oDataList = new List<List<object>>();
using (DbDataReader dr = command.ExecuteReader())
{
if (dr.HasRows)
{
while (dr.Read())
{
List<object> oData = new List<object>();
for (int i = 0; i < dr.FieldCount; i++)
{
oData.Add(dr[i]);
}
oDataList.Add(oData);
}
}
dr.Close();
}
return oDataList;
}
}
我尝试通过以下方法将其转换为二维对象数组:
object[,] myNewObjectArray = oDataArray.GetDataObject(anyDbCommand).ToArray<object>().ToArray<object>();
但它不起作用!? :( 我做错了什么?
答案 0 :(得分:1)
怎么样,
oDataArray.GetDataObject(anyDbCommand).Select(a =&gt; a.ToArray())。ToArray();
一些解释: