这是我的函数:
private IEnumerable<string> SeachItem(int[] ItemIds)
{
using (var reader = File.OpenText(Application.StartupPath + @"\temp\A_A.tmp"))
{
var myLine = from line in ReadLines(reader)
where line.Length > 1
let id = int.Parse(line.Split('\t')[1])
where ItemIds.Contains(id)
let m = Regex.Match(line, @"^\d+\t(\d+)\t.+?\t(item\\[^\t]+\.ddj)")
where m.Success == true
select new { Text = line, ItemId = id, Path = m.Groups[2].Value };
return myLine;
}
}我得到一个编译错误,因为"myLine“不是IEnumerablestring,而且我不知道如何编写IEnumerableAnonymous
“无法将类型'System.Collections.Generic.IEnumerableAnonymousType#1‘隐式转换为'System.Collections.Generic.IEnumerablestring'”
发布于 2021-09-28 18:19:57
此链接可能对最终在此处https://idreesdotnet.blogspot.com/2019/08/c-how-to-create-list-of-anonymous-type.html的其他人很有用
第一个解决方案(共6个)非常简单
1:首先创建匿名类型的对象,然后将其传递给数组并调用ToList()方法。
var o1 = new { Id = 1, Name = "Foo" };
var o2 = new { Id = 2, Name = "Bar" };
var list = new[] { o1, o2 }.ToList();https://stackoverflow.com/questions/901854
复制相似问题