本文介绍了如何使缓冲区为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在程序中使用list int作为缓冲区 我需要检查条件之后我需要将缓冲区清空 如果 (buffer1.Count!= 0 ) { int largestVal = buffer1 [ 0 ]; foreach ( int temp in buffer1) { if (temp > largestVal) largestVal = temp; f2 = largestVal; } for ( int z = f2 + 1 ; z < k - 1 ; z ++ ) { if ((CANMsgIdList [i] .MsgId == CANMsgIdList [z] .MsgId)) { buffer2 [q2] = z; } } } // buffer1 = null; 整个代码在for循环中运行。 我是在行处获得null异常(buffer1.Count!= 0) 错误:对象引用未设置为对象的实例。解决方案 如果 buffer1 是 List< int> < / int> 你必须调用 buffer1.Clear()才能清空它。 如果您在行上收到空引用错误: if (buffer1.Count!= 0 ) 那么唯一可能的原因是butter1为null:即你没有赋值给在任何地方。尝试查看对它的所有引用,并查找指定buffer1的位置(并且指定的值可能是 null )或代码中的某处应该是写一些类似的东西: buffer1 = new List< int>(); 但不是! Hi,I am using list int as buffer in my programI need to check a condition after that I need to make buffer empty if (buffer1.Count != 0){ int largestVal = buffer1[0]; foreach (int temp in buffer1) { if (temp > largestVal) largestVal = temp; f2 = largestVal; } for (int z = f2 + 1; z < k - 1; z++) { if ((CANMsgIdList[i].MsgId == CANMsgIdList[z].MsgId)) { buffer2[q2] = z; } } } //buffer1 = null;The whole code is running in a for loop.I am getting null exception at the line (buffer1.Count != 0)Error: Object reference not set to an instance of an object. 解决方案 If buffer1 is a List<int> </int>you have to call buffer1.Clear() in order to empty it.If you are getting a null reference error on the line:if (buffer1.Count != 0)Then the only possible reason is that butter1 is null: i.e. you have not assigned a value to it anywhere. Try looking at all the references to it, and look for either places where you assign buffer1 (and the assigned value could be null) or for somewhere in the code where you should be writing something like:buffer1 = new List<int>();but aren't! 这篇关于如何使缓冲区为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-29 07:37