Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望将 C# 中 List 数据类型的所有索引放入任何整数数组中。那可能吗?我试过这个:
ckey = Command.IndexOf("Callers:");
哪里ckey是一个int[]和Command是List<String>。
ckey
int[]
Command
List<String>
int[] indices = Enumerable.Range(0, Command.Count).ToArray();
编辑:如果你想找到给定字符串的索引,你可以这样做:
string toFind = // int[] indices = strs.Select((s, idx) => new { Str = s, Idx = idx }) .Where(p => p.Str == toFind) .Select(p => p.Idx) .ToArray();