I have a byte list variable which I store byte array information here:
internal List<Byte> portBuffer = new List<Byte>();
And I have another byte array variable:
byte[] ret_bytes = { 0x4F, 0x4B };
How can I find out if ret_bytes is inside the portBuffer? The code below seems like not correct.
portBuffer.Contains(ret_bytes)
Another question, how to find out the position of the first element of ret_bytes in side the portBuffer list if it is inside the list?
Thanks
Containsdoesn’t find one sequence within another, it finds one element within a sequence – I don’t believe there’s anything within .NET which will do what you want out of the box.It’s up to you whether you write a very general purpose implementation or one that just solves your current issue – the former is likely to be more work, but may pay dividends in the long run.
If you only need to find two bytes, I’d be tempted to just iterate: