查找项目的索引多维数组 [英] Find index of item in a multidimensional array

查看:137
本文介绍了查找项目的索引多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个多维数组:

 暗淡测试(,,)作为字符串

我如何遍历数组找到,如果另一个变量是包含在数组的第二维?



显然,这是行不通的:

 暗淡x As中整数= test.IndexOf(otherVariable )


解决方案

您是否尝试过LINQ?或许沿(伪代码杂交)线的东西:

  VAR X =(从测试
项其中,item.IndexOf(OtherVariable)> = 0
选择item.IndexOf(OtherVariable))的SingleOrDefault()。

$ B $:



仅供参考,如果你声明的数组像这样的,而不是这应该工作b

 的String [] []测试


If I have a multidimensional array:

Dim test(,,) As String

How can I loop through the array to find if another variable is contained in the second dimension of the array?

Obviously, this won’t work:

Dim x As Integer = test.IndexOf(otherVariable)

解决方案

Have you tried LINQ? Perhaps something along the lines of (pseudo-code-ish):

var x = (from item in test
         where item.IndexOf(OtherVariable) >= 0 
         select item.IndexOf(OtherVariable)).SingleOrDefault();

FYI, this should work if you declare your array like this instead:

string[][] test

这篇关于查找项目的索引多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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