说我有这样的数组
string [] fruits = {"watermelon","apple","kiwi","pear","banana"};
fruits.FindAllIndex("apple");
将返回1和2的数组
如果没有,我该如何实施呢?
谢谢!
解决方法
一种方法是这样写:
var indices = fruits .Select ((f,i) => new {f,i}) .Where (x => x.f == "apple") .Select (x => x.i);
或传统方式:
var indices = new List<int>(); for (int i = 0; i < fruits.Length; i++) if(fruits[i] == "apple") indices.Add(i);