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
就像这样
myList.RemoveAll(b => b == 0);
bytes.RemoveAll(x => x == 0)
How about using List.RemoveAll() method?
Removes all the elements that match the conditions defined by the specified predicate.
YourList.RemoveAll(n => n == 0);
For example;
List<int> list = new List<int>(){5, 3, 0, 0, 17};
list.RemoveAll(n => n == 0);
foreach (var i in list)
{
Console.WriteLine(i);
}
Output will be;
5
3
17
Here is a DEMO .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.