你如何转换List< DataRow> list1成一个数组 [英] How do you convert List<DataRow> list1 into an array

查看:111
本文介绍了你如何转换List< DataRow> list1成一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将特定的数据行读入数组。我知道如何让我的excel文件读取,但我不知道如何将一个特定的行放入一个数组....请帮助我了解如何声明一个动态数组!我目前正在尝试使用List但我正在努力将其转换为数组。 (该行包含数字)

解决方案

根据我的理解,您想要转换

 List< DataRow>到数组列表



在这种情况下,你可以按照以下两种方式

 var lst = new List< datarow> ;(); 



1.使用LINQ

 List< object []> lstObj = lst.Select((x)=> x.ItemArray)。ToList(); 



2.使用foreach

 var lstobj = new List< object []>(); 
foreach(lst中的DataRow drTemp)
lstobj.Add(drTemp.ItemArray);









假设您想要从

 List< DataRow> 

转换为完成数组,那么您可以按照以下代码

 var newobj = lst.Select((x)=> x.ItemArray)。ToArray(); 


< blockquote>看看这里: List< t> .ToArray Method [ ^

I am trying to read a specific row of data into an array. I know how to get my excel file to read but i do not know how to get a specific row into an array....Please help me understand how to declare a dynamic array! I am currently trying to use a List but I am struggling to convert it to an array. (The row contains numbers)

解决方案

As per my understanding you wants to convert

List<DataRow> to List of array


In that case you can follow the below two ways

var lst = new List<datarow>();


1. using LINQ

List<object[]> lstObj = lst.Select((x) => x.ItemArray).ToList();


2. using foreach

var lstobj = new List<object[]>();
     foreach (DataRow drTemp in lst)
     lstobj.Add(drTemp.ItemArray);





Suppose if you want to convert from

List<DataRow>

to complete array, then you can follow the below code

var newobj = lst.Select((x) => x.ItemArray).ToArray();


Have a look here: List<t>.ToArray Method[^]


这篇关于你如何转换List&lt; DataRow&gt; list1成一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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