我正在解决我在C#中解决的问题的解决方案,但现在我将我的代码移植到F#.我有一个字节数组,我需要在这个数组中搜索两个值(x,y).当我找到时x,需要检查:如果y是下一个索引,我们有匹配.如果y不在下一个索引上,搜索将继续.我该如何解决这个问题?我试图使用Array.findIndex,但没有成功,因为我不知道如何继续搜索时y不在下一个索引.
编辑:
public void GetValue(byte[] data)
{
byte[] temp = new byte[4];
for (int i = 0; i < data.Length; i++)
{
if (data[i] == Adress[0] && data[i + 1] == Adress[1])
{
for (int j = 0; j < temp.Length; j++)
{
temp[j] = data[j + i + 2];
}
Value = BitConverter.ToInt32(temp, 0) * 0.01;
break;
}
}
Run Code Online (Sandbox Code Playgroud)