Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing empty bytes from List<byte>

Tags:

arrays

c#

list

How do I delete empty bytes from a List<byte>?

For example I got a list with a size of [5].

[0] = 5
[1] = 3
[2] = 0
[3] = 0
[4] = 17

At this example I want to delete byte with index: 2 and 3.

The Items in the list change every second. So the next time the list could be filled with something like:

[0] = 0
[1] = 2
[2] = 3
[3] = 4
[4] = 0
like image 738
Max Avatar asked Jul 24 '26 01:07

Max


2 Answers

It's something like

myList.RemoveAll(b => b == 0);
like image 101
Rawling Avatar answered Jul 25 '26 14:07

Rawling


bytes.RemoveAll(x => x == 0)
like image 34
Matthew Watson Avatar answered Jul 25 '26 14:07

Matthew Watson