C# ArrayList容量不超过32768
我有一个从数据库返回大量行的方法。(请参阅下文) 当我运行这个方法时,我意识到custcol.InnerList的计数是32767,应该是34000左右。然后我看到它进入了异常状态 错误消息表示“值对于Int16太大或太小。” 我相信,这个数组列表的容量在某种程度上被分配为int16。有人能帮我增加容量吗 谢谢 编辑: 这是完整的堆栈跟踪C# ArrayList容量不超过32768,c#,arraylist,collections,C#,Arraylist,Collections,我有一个从数据库返回大量行的方法。(请参阅下文) 当我运行这个方法时,我意识到custcol.InnerList的计数是32767,应该是34000左右。然后我看到它进入了异常状态 错误消息表示“值对于Int16太大或太小。” 我相信,这个数组列表的容量在某种程度上被分配为int16。有人能帮我增加容量吗 谢谢 编辑: 这是完整的堆栈跟踪 at System.Convert.ToInt16(Int64 value) at System.Int64.System.IConvertibl
at System.Convert.ToInt16(Int64 value)
at System.Int64.System.IConvertible.ToInt16(IFormatProvider provider)
at System.Convert.ToInt16(Object value)
at Quest___Shared.CustomerCrossReference.ListFromReader(IDataReader reader) in C:\vsproject\CustomerCrossReference.cs:line 105
at Quest___Shared.ACollection.GetListFromDatabase(String customernumber) in C:\vsproject\ACollection.cs:line 88
将给您带来问题的变量类型更改为
Int32
或Int64
,这样您就可以插入更大或更小的数字。数据表可以容纳16777216行是否确定数组列表有问题?ACollection.ListFromReader
的实现是否尝试将大的32位或64位列值分配给cust
的16位属性?或者,它可能正在为ushort
属性指定一个负值列?能够看到异常的整个堆栈跟踪可能有助于确定这一点。我怀疑您的分析。但无论如何,ArrayList都非常不受欢迎。使用列表代替!
at System.Convert.ToInt16(Int64 value)
at System.Int64.System.IConvertible.ToInt16(IFormatProvider provider)
at System.Convert.ToInt16(Object value)
at Quest___Shared.CustomerCrossReference.ListFromReader(IDataReader reader) in C:\vsproject\CustomerCrossReference.cs:line 105
at Quest___Shared.ACollection.GetListFromDatabase(String customernumber) in C:\vsproject\ACollection.cs:line 88