Convert bool[] to byte[]

前端 未结 7 1771
野趣味
野趣味 2020-12-09 06:32

I have a List which I want to convert to a byte[]. How do i do this? list.toArray() creates a bool[].

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 06:36

    If you have any control over the type of list, try to make it a List, which will then produce the byte[] on ToArray(). If you have an ArrayList, you can use:

    (byte[])list.ToArray(typeof(byte));
    

    To get the List, you could create one with your unspecified list iterator as an input to the constructor, and then produce the ToArray()? Or copy each item, casting to a new byte from bool?

    Some info on what type of list it is might help.

提交回复
热议问题