C# 如何将索引字段添加到Linq SelectMany结果

C# 如何将索引字段添加到Linq SelectMany结果,c#,lambda,C#,Lambda,我有一个简单的选择 List<string> animal = new List<string>() { "cat", "dog", "donkey" }; List<int> number = new List<int>() { 10, 20 }; var result = number.SelectMany((num, index) => animal, (n, a) => index + n + a ); // expected

我有一个简单的选择

List<string> animal = new List<string>() { "cat", "dog", "donkey" };
List<int> number = new List<int>() { 10, 20 };
var result = number.SelectMany((num, index) => animal, (n, a) => index + n + a );

// expected result: 0cat10, 1dog10, 2donkey10, 3cat20, 4dog20, 5donkey20
List animal=newlist(){“猫”、“狗”、“驴”};
列表编号=新列表(){10,20};
变量结果=数字。选择多个((数字,指数)=>动物,(n,a)=>指数+n+a);
//预期结果:0cat10、1dog10、2donkey10、3cat20、4dog20、5donkey20

我想添加索引,但我想不出正确的语法

将索引从SelectMany中删除:

List<string> animals = new List<string> { "cat", "dog", "donkey" };
List<int> numbers = new List<int> { 10, 20 };
var output = numbers.SelectMany(n => animals.Select(s => s + n))
                    .Select((g,i) => i + g);
List<string> animal = new List<string>() { "cat", "dog", "donkey" };
List<int> number = new List<int>() { 10, 20 };
var index = 0;
var result = number.SelectMany(n => animal, (n, a) => index++ + a + n );
List animal=newlist(){“猫”、“狗”、“驴”};
列表编号=新列表(){10,20};
var指数=0;
var result=number.SelectMany(n=>animal,(n,a)=>index+++a+n);

将索引从SelectMany中删除:

List<string> animal = new List<string>() { "cat", "dog", "donkey" };
List<int> number = new List<int>() { 10, 20 };
var index = 0;
var result = number.SelectMany(n => animal, (n, a) => index++ + a + n );
List animal=newlist(){“猫”、“狗”、“驴”};
列表编号=新列表(){10,20};
var指数=0;
var result=number.SelectMany(n=>animal,(n,a)=>index+++a+n);

不错。“我想没有办法把所有的东西都放进SelectMany?”fubo GreenEyedAndy用单曲提出了这个方法SelectMany@fubo我用single
SelectMany
添加了解决方案,但它看起来不太好。“我想没有办法把所有的东西都放进SelectMany?”fubo GreenEyedAndy用单曲提出了这个方法SelectMany@fubo我用single
SelectMany添加了解决方案,但它看起来不太好