Working with byte arrays in C#

前端 未结 1 604
盖世英雄少女心
盖世英雄少女心 2021-02-07 17:44

I have a byte array that represents a complete TCP/IP packet. For clarification, the byte array is ordered like this:

(IP Header - 20 bytes)(TCP Header - 20 bytes)(Payl

相关标签:
1条回答
  • 2021-02-07 18:16

    A common practice you can see in the .NET framework, and that I recommend using here, is specifying the offset and length. So make your Parse function also accept the offset in the passed array, and the number of elements to use.

    Of course, the same rules apply as if you were to pass a pointer like in C++ - the array shouldn't be modified or else it may result in undefined behavior if you are not sure when exactly the data will be used. But this is no problem if you are no longer going to be modifying the array.

    0 讨论(0)
提交回复
热议问题