越来越多指标从通过单个值 [英] Getting multiple indexes from passing single value

查看:105
本文介绍了越来越多指标从通过单个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  列表索引搜索

我有一个int [],其中值是相同的,因此我必须得到所有在INT []相同值的索引NUM拿到指标。

I have to get index in an int[] where value would be the same and thus I have to get all the index num for the same value in the int[].

恩。

int[] xx = {4,5,4,3,2}

我使用

Array.indexOf(xx, 4);

返回0,但我希望得到0和2。

it will return 0 but I want to get 0, and 2.

推荐答案

如何

int[] xx = {4,5,4,3,2};

int search = 4;

var result = xx.Select((b, i) => b.Equals(search) ? i : -1).Where(i => i != -1);

这里阅读我原来的答复

Read my original answer here.

这篇关于越来越多指标从通过单个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆