我有一个 string[]
,想获取 string[]
中有索引的元素,我知道它存在,在 int[]
中指定。
string[] stringArray = { "a", "b", "c", "d", "e", "f", "g" };
int[] indices = { 1, 2, 4, 6 };
据此,我试图获得一个包含 { "b", "c", "e", "g"}
的 string[]
。最好使用 lambda 表达式。我该怎么做?
最佳答案
你可以这样做的一种方法是这样的。
string[] result = indices.Select(i => stringArray[i]).ToArray()
关于c# - 获取索引为 int[] indices 的 string[] 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9739674/