我有一个这样的文件:填充列表<Object>使用LINQ
City|Country|Phone Number
Name
City|Country|Phone Number
Name
City|Country|Phone Number
Name
等等...
我做了一个类:
class Person
{
string city, country, phone, name;
}
阅读这个大后文件,我想创建一个List并将所有值放在它们各自的字段中。
我的工作至今
List<PersonObj> objectsList = new List<PersonObj>();
string[] peopleFile = System.IO.File.ReadAllLines(fileName);
var oddLines = peopleFile.Where((src, index) => index % 2 != 0);
var evenLines = peopleFile.Where((src, index) => index % 2 == 0);
和其分别成功获取地址和名称分别线在oddLines
和evenLines
。
我想要的东西
我应该objectsList填充使用LINQ,而不是使用循环
非常感谢您的帮助
你是什么意思 “在一线” 是什么意思? –
@BrianMains哦,我的意思是直接使用LINQ。我已更新问题 –