Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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
22nd Oct 2022, 4:41 PM
SoloProg
SoloProg - avatar
+ 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..
22nd Oct 2022, 3:49 PM
Jayakrishna 🇮🇳
+ 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); } }
23rd Oct 2022, 4:24 PM
khabz01
khabz01 - avatar
0
Hii
24th Oct 2022, 1:37 AM
Aditya Garg
Aditya Garg - avatar