❔ Array.IndexOf being weird
I'm very confused. Been trying to use Array.IndexOf to find a null terminator in a byte array
But it fails to find the byte and returns -1
Doing this however, it finds the byte... O_O
Why does Array.IndexOf not work in this situation?
11 Replies
.IndexOf() has a generic overload. Do
.IndexOf<byte>()
and it should workyou're a lifesaver... weird that it doesn't detect the type. What is the type by default?
It looks like it doesn't care about that from the parameters, it's looking for an 'object?' in 'Array'
Depends on your variable type whether the generic overload would be picked
That seems dumb to me. So in some cases we just have to explicitly state the type but in other cases it will figure it out?
C# be quirky
Also relevant. When you put in 0x0 it defaulted to an int
that makes more sense
So it couldn't apply IndexOf<byte> to byte[] and int
gotcha. Thank you for the help 🙂
What type is Data declared as?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.