I have a byte Array that contains the char '%' (25 hex, 37 decimal). I would like to get the index of this byte, however, none of these methods work, and -1 is returned. How to get the index of a specific byte in a byte array?
int byteIndex = Array.IndexOf(bytesDataArray, '%');
int byteIndex = Array.IndexOf(bytesDataArray, 37);
int byteIndex = Array.IndexOf(bytesDataArray, 0x25);
You're trying to find an int value of 37 in a byte array. Byte arrays don't contain ints. You need to do a type cast:
int byteIndex = Array.IndexOf(bytesDataArray, (byte)37);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.