Get return de positión of an element in a multple integer list int[]

how to get the position of an element inside an int [] with a variable. for example within a roster I get a shared code for 10 members of a household int [1,1,23,23,4,5,67,67,67,8], then I apply Distinct () and I get int [1, 23,4,5,67,8], then I want to obtain the index of each of the original list values in the list with unique cases, this with the option that each row obtain a value from 1 to 8, allowing me to replace values like 23, 67.

It’s unclear what you want to achieve.

If you are using list roster every household member will have it’s unique code that identifies it: @rowcode.

Please elaborate your goal to get more specific answer

I need the index of an element:
Example: [1,10, 50].FindIndex(10) should return 1

Here is an example how to iterate over all household members in order, assigning index to every group.
Assuming you have long variable in roster that named selector.
The following code selects collection of new objects, preserving @rowcode, groups them by selector,
sorts those groups by selector value, and selects a new collection with new index in order.
So if you have array of corresponding values of selector: [1,1,23,23,4,5,67,67,67,8] you will get

0->{1, rowcodeC}, {1, rowcodeA}
1->{4, rowcodeV}
2->{5, rowcodeS}
3->{8, rowcodeO}
4->{23, rowcodeW}, {23,rowcodeN}

            foreach (var item in roster
                .Select(x => new { x.selector, x.@rowcode })
                .GroupBy(x => x.selector)
                .OrderBy(y => y.Key)
                .Select((group, index) => new { group, index }))
                foreach (var hhmember in
                    //item.index - new index in order, starting 0
                    // original rowcode - hhmember.rowcode
                    //address household member by rowcode

Would you mind to describe your problem in more generic terms?
Something like this:
I have a roster that represents household members that is triggered by list questions.
In the roster there is a question\variable that askes the level or education, for instance.
I want to get all people of 3rd and 4th level and ask only those extra questions.

@Ricardo_pizarro , if your variable is an int[], you could use the IndexOf() function, which is described with details here:

In general however, you will find more often that data in Survey Solutions is stored differently, not directly in arrays, and you may need a conversion of data types.

1 Like

amazing! It worked perfectly, thank you very much for your timely response.

Sure. Glad that you’ve found a solution for your question!