DataTable 行的第一列到字符串数组
我有一个数据表。我想获取每行第一列值并附加到字符串数组。我不想对每一行使用 foreach 循环并添加到字符串数组。我尝试过这个,但在某些时候卡住了
DataRow[] dr = new DataRow[dtCampaignSubscriberLists.Rows.Count];
dtCampaignSubscriberLists.Rows.CopyTo(dr, 0);
string[] array = Array.ConvertAll(dr, new Converter<DataRow, String>(????));
谢谢
I have a DataTable. I want to get every rows first column value and append to a string array. I do not want to use foreach looping for every row and adding to string array. I tried this, but stuck at some point
DataRow[] dr = new DataRow[dtCampaignSubscriberLists.Rows.Count];
dtCampaignSubscriberLists.Rows.CopyTo(dr, 0);
string[] array = Array.ConvertAll(dr, new Converter<DataRow, String>(????));
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行以下操作:
dtCampaignSubscriberLists.AsEnumerable().Select(r => r[0].ToString()).ToArray();
You could do something like:
dtCampaignSubscriberLists.AsEnumerable().Select(r => r[0].ToString()).ToArray();