C# convert from uint[] to byte[]

后端 未结 5 1988
[愿得一人]
[愿得一人] 2021-01-13 20:35

This might be a simple one, but I can\'t seem to find an easy way to do it. I need to save an array of 84 uint\'s into an SQL database\'s BINARY field. So I\'m using the fol

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-13 20:48

    byte[] byteArray = Array.ConvertAll(
        uintArray,
        new Converter(
            delegate(uint u) { return (byte)u; }
        ));
    

    Heed advice from @liho1eye, make sure your uints really fit into bytes, otherwise you're losing data.

提交回复
热议问题