In C# how can I truncate a byte[] array

后端 未结 6 764
太阳男子
太阳男子 2021-01-03 18:27

I have a byte[] array of one size, and I would like to truncate it into a smaller array?

I just want to chop the end off.

6条回答
  •  忘掉有多难
    2021-01-03 18:48

    Arrays are fixed-size in C# (.NET).

    You'll have to copy the contents to a new one.

    byte[] sourceArray = ...
    byte[] truncArray = new byte[10];
    
    Array.Copy(sourceArray , truncArray , truncArray.Length);
    

提交回复
热议问题