I have byte buffer:
byte[] buffer = new byte[3];
List<byte[]> list;
Now I am adding:
while ((count = reader.Read(buffer, 0, buffer.Length)) != 0)
{
bool contains = l.Contains<byte[]>(buffer); //This is not working and checking only reference
if (!contains)
{
l.Add(new byte[] buffer[0],buffer[1],buffer[2]});
}
}
How to check if list contains byte array wchich has the same values as buffer?
Your current version is not working because it does a check based on reference equality.
You want to find out if any list elements contain the same sequence of bytes:
bool contains = list.Any(x => x.SequenceEqual(buffer));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With