using System;
using System.Collections.Generic;
public class Program
{
public static List<byte> RemoveTrailingNulls(List<byte> byteList) {
while (byteList.Count > 0 && byteList[byteList.Count - 1] == 0) {
byteList.RemoveAt(byteList.Count - 1);
}
return byteList;
}
public static void Main()
{
List<byte> byteList = new List<byte> { 1, 2, 3, 0, 0, 0, 0 };
List<byte> trimmedList = RemoveTrailingNulls(byteList);
foreach (byte b in trimmedList) {
Console.Write(b + " ");
}
}
}
/*
run:
1 2 3
*/