1.list会不上线的增加,增加硬件内存,需要剔除数据:
List<int> erf = new List<int> {1,2,3,4,5 }; if (erf.Count>3) { erf.RemoveAt(0);
//erf.RemoveRange(0,2); }
2.remove不能移除类或者数组等格式数据,否则会报错false、
static List<ZLGCANMessage> cANMessageAlls = new List<ZLGCANMessage>();
public class ZLGCANMessage { /// <summary> /// CANID /// </summary> public uint CANID { get; set; } /// <summary> /// CAN长度 /// </summary> public byte lenData { get; set; } /// <summary> /// CAN周期 /// </summary> public int period { get; set; } /// <summary> /// CAN发送类型,0正常,1单词,2自发自收,3单次自发自收,默认固定0 /// </summary> public byte sendType { get; set; } /// <summary> /// 0:data frame数据帧,1:remote frame远程帧 /// </summary> public byte remoteFlag { get; set; } /// <summary> /// type帧类型,0:standard frame标准帧,1:extend frame扩展帧 /// </summary> public byte externFlag { get; set; } /// <summary> /// 数据 /// </summary> public byte[] Data { get; set; } public string DataString { get; set; } /// <summary> /// CAN发送协议,0CAN,1CANFD /// </summary> public byte protocol { get; set; } /// <summary> /// CANFD是否加速,0不加速,1加速 /// </summary> public byte CANFDExp { get; set; } }
直接remove一样的类类型会false:cANMessageAlls.Remove(cANMessage);
原因是remove中是泛型T item
需要具体定义一下移除数据:
var whereRemove = cANMessageAlls.FirstOrDefault(t=>t.DataString== canMessage.DataString /*t => t.CANID == canMessage.CANID*/);
cANMessageAlls.Remove(whereRemove);
注意,如果其中的t定义的不是string类型,而是date数组这个参数时候,var为空