这是我的代码 我需要通过匹配构造函数中的char值来找到对象的索引。
Transition[][] transitions = new Transition[3][]
{
new Transition[] {new Transition ('+',1), new Transition('-',1 ) , new Transition('0',1), new Transition('1', 1), new Transition('2', 1) } ,
new Transition[] {new Transition('0', 2), new Transition ('1',2) , new Transition('2',2) },
new Transition[] {new Transition ('0',2) , new Transition( '1',2 ), new Transition('2',2) }
};
答案 0 :(得分:0)
每个字符匹配都有2个索引值。并且有多种可能的结果。
因此,确定索引的方法应该类似于
public static IEnumerable<Tuple<int, int>> GetIndexes(Transition[][] Items, char SearchChar)
{
for (int i = 0; i < Items.Length; i++)
{
for (int j = 0; j < Items[i].Length; j++)
{
if (Items[i][j].charItem == SearchChar) // charItem is the name of your property
{
yield return new Tuple<int, int>(i, j);
}
}
}
}
用法:
var Result = GetIndexes(transitions, '1'); //(0,3)(1,1)(2,1)