Warm tip: This article is reproduced from serverfault.com, please click

c#-如何通过索引用LINQ用整数数组过滤String数组?

(c# - How to filter String array with integer array with LINQ by index?)

发布于 2020-11-28 16:09:10
String[] columnList = new String[]{"column1","column2","column3","column4","column5","column6","column7","column8","column9","column10","column11","column12" };

Int[] fList = new Int[] { 1,3,5,10,12 };

我想要这样的输出:

column1,column3,column5,column10,column12
Questioner
Sunder Sakthivel
Viewed
0
Igor Pashchuk 2020-11-29 00:26:34

我希望这不是功课!这将达到目的:

var joined = from column in columnList.Select((x, i) => new {Index = i + 1, Column = x} )
             join index in fList on column.Index equals index
             select column.Column;
Console.WriteLine(string.Join(",", joined));

// output
// column1,column3,column5,column10,column12