making a list using inner query in Linq in C#(在 C# 中使用 Linq 中的内部查询制作列表)
问题描述
我正在尝试使用 Linq 创建一个子列表,但不明白其中的错误.我不认为我做错了,但我认为其他人的眼睛会帮助我解决这个问题.
I am trying to create a sublist using Linq but don't understand the error in this. I don't think i am doing wrong but i think others eye will help me to sort this issue.
var dataList = File.ReadAllLines(inputFile);
dataList = from line in dataList
let temp = from data in line.Split(';').ToList()
where line.Split(';').ToList().IndexOf(data) != 0 ||line.Split(';').ToList().IndexOf(data) != 1
select data
select string.Join(",",temp);
我收到错误消息说 IEnumerable 列表不能隐式转换为 string[]..:(
I am getting error saying that IEnumerable list cannot be implicitly converted to string[]..:(
推荐答案
dataList是一个数组,而LINQ返回的是IEnumerable.将 ToArray 添加到查询的末尾:
dataList is an array, while LINQ returns IEnumerable<string>. Add ToArray to the end of the query:
dataList = (from line in dataList
let temp = from data in line.Split(';').ToList()
where line.Split(';').ToList().IndexOf(data) != 0 || line.Split(';').ToList().IndexOf(data) != 1
select data
select string.Join(",", temp)).ToArray();
这篇关于在 C# 中使用 Linq 中的内部查询制作列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中使用 Linq 中的内部查询制作列表
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
