在数组中查找包含值的对象的最快方法是什么?
例如,我需要找到对象 orange 的数组索引(其索引 1 )。
(StandardClasses数组)
[
{"apple":
{"color" : "green", "shape" : "round"}
},
{"orange":
{"color" : "orange", "shape" : "round"}
},
{"banana":
{"color" : "yellow", "shape" : "long"}
}
]
答案 0 :(得分:-1)
无需为每个声明找到索引用户更清洁 foreach语句将在您的数组中循环
foreach(var item in YourArray){//do your logic here}