我有以下代码:
public class Info
{
public string Name;
public string Num;
}
string s1 = "a,b";
string s2 = "1,2";
IEnumerable<Info> InfoSrc =
from name in s1.Split(',')
from num in s2.Split(',')
select new Info()
{
Name = name,
Num = num
};
List<Info> listSrc = InfoSrc.ToList();
我希望我的
listSrc
结果包含两个Info
项,其Name
和Num
属性分别为:a, 1
b, 2
然而,我展示的代码会得到四个项目:
a, 1
a, 2
b, 1
b, 2
Enumerable.Zip
方法。 - Kvam