+ 3
// Lia , hope this helps
int[] nums = {42, 8, 4, 16, 23, 15, 16};
var idxs16 = nums
.Select((num, idx) => new { idx, num })
.Where(itm => itm.num == 16);
foreach(var itm in idxs16) Console.WriteLine(itm.idx);
https://www.sololearn.com/compiler-playground/cOLP7bD1pjoE
+ 2
IndexOf(element):
n = list.IndexOf(16) will return index of it's first occurrence from list. If not exist then returns -1.
IndexOf( element, n) :
Adding second to IndexOf method like
list.IndexOf(16, n ) will search 16 from index n, (not from start) so you can pass previous Index found here as n (by first method, at first you can pass as 0 ) So that it will return next occurence of 16 index value. If not found, returns -1.
You can loop this until it returns -1 or no more element 16...
Hope it helps..
+ 2
//loop version
int[] nums = {42, 8, 4, 16, 23, 15, 16};
for(int i = 0; i < list.Length; i++){
if( list[i] == 16){
Console.WriteLine(i);
}
}
0
Hii