我的输入数据是一个列表行,如下所示,称之为行
author1::author2::author3 - title
我创建了一个提取作者和标题的函数:
ExtractNameAndAuthors(string line, out string title, IList<string> authors)
我现在想使用以下形式的 Linq 创建一个查找 (ILookup) 对象:
key: title
value: list of authors
有人真正精通 Linq 吗?
最佳答案
var list = new []{"author1::author2::author3 - title1",
"author1::author2::author3 - title2",};
var splited = list.Select(line => line.Split('-'));
var result = splited
.ToLookup(line => line[1],
line => line[0].Split(new[]{"::"}, StringSplitOptions.RemoveEmptyEntries));
关于c# - 如何使用 Linq 从列表列表创建查找?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16062849/