Home > Net >  Index is equal to or greater than the length of the array, or the number of elements in the dictiona
Index is equal to or greater than the length of the array, or the number of elements in the dictiona

Time:09-17

Quote is the following error
[OnH1Work error index is equal to or greater than the length of the array, or the number of elements in the dictionary is greater than the available space at the end of an array of the index and the target, in the System. The Collections. The Concurrent. The ConcurrentDictionary ` 2. System. Collections. The Generic. ICollection & gt; the CopyTo (KeyValuePair ` 2 [] array, Int32 index)
In the System. Collections. Generic. List ` 1.. Ctor (IEnumerable collection ` 1)
In the System. The Linq. Enumerable. ToList [TSource] (IEnumerable ` 1 source)
In the Device. MainControl. GetTestItem ()
In the Device. MainControl. OnH1Work ()]

Source:

Define ConcurrentDictionary ScanBarAfterItemList=new ConcurrentDictionary (a);



Private SendItemModel GetTestItem ()
{
SendItemModel itemModel=null;
List TempSortList=this. ScanBarAfterItemList. ToList ();
String curKey=string. The Empty;
TempSortList. Sort (enclosing sortList);
The foreach (KeyValuePair The item in tempSortList)
{
CurKey=item. The Key;
This. ScanBarAfterItemList. TryGetValue (curKey, out itemModel);
If (itemModel!=null & amp; & ItemModel. ItemStatus==EnumItemTestStatus. ITSSendToThread)
{
Return itemModel.
}
}

return null;
}


This is where the fault, look not to come out, please help me

CodePudding user response:

Feeling is the enclosing scanBarAfterItemList. TryGetValue (curKey, out itemModel);
You put the SendItemModel itemModel=null; To SendItemModel itemModel=new SendItemModel (); Give it a try
  • Related