gpt4 book ai didi

c# - 索引超出范围错误,如果不是

转载 作者:行者123 更新时间:2023-11-30 17:55:07 28 4
gpt4 key购买 nike

我有以下方法:

private void DetermineIfWagerIsValid(CouponViewModel result, Bet bet, string wagerType, int selectionCount)
{
if (bet.Wagers[0].WagerType == wagerType) //error here
{
if (bet.Selections.Count != selectionCount)
{
bet.BetStatus = BetStatus.FilledInAndInvalid;
}
}
}

很简单,但是当索引似乎没有超出范围时,我会间歇性地收到“索引超出范围”错误:

Out of range

这是 StackTrace:

at System.ThrowHelper.ThrowArgumentOutOfRangeException() at System.Collections.Generic.List1.get_Item(Int32 index) at
System.Collections.ObjectModel.Collection
1.get_Item(Int32 index)
at Arkle.CouponProcessing.Scan.LonglistDecoder_994550.DetermineIfWagerIsValid(CouponViewModel result, Bet bet, String wagerType, Int32 selectionCount) in c:\code\Arkle\Arkle\Arkle.CouponProcessing\Scan\LonglistDecoder_994550.cs:line 117 at Arkle.CouponProcessing.Scan.LonglistDecoder_994550.DetermineIfBetIsValid(CouponViewModel result) in c:\code\Arkle\Arkle\Arkle.CouponProcessing\Scan\LonglistDecoder_994550.cs:line 107 at Arkle.CouponProcessing.Scan.LonglistDecoder_994550.Decode() in c:\code\Arkle\Arkle\Arkle.CouponProcessing\Scan\LonglistDecoder_994550.cs:line 62 at ArkleWPF.UI.SlipScanning.CouponTools.DecodeCoupon(Image img, OMRForm omrForm1, CouponDecoder decoder, CouponPrintingInformation viewSettings, String slipBarcode, DecodeStatus status) in C:\code\Arkle\Arkle\ArkleWPF\UI\SlipScanning\CouponTools.vb:line 215
at ArkleWPF.UI.SlipScanning.CouponTools.ProcessForm(OMRForm omrForm1, DecodeStatus status, CouponPrintingInformation viewSettings, Boolean alwaysLotto) in C:\code\Arkle\Arkle\ArkleWPF\UI\SlipScanning\CouponTools.vb:line 89
at ArkleWPF.UI.SlipScanning.CouponTools._Closure$__1._Lambda$__1() in C:\code\Arkle\Arkle\ArkleWPF\UI\SlipScanning\CouponTools.vb:line 27
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

这不是每次都发生,更像是每隔两三次发生,这让我抓狂!有什么想法吗?

最佳答案

 System.Collections.Generic.List1.get_Item(Int32 index) at
System.Collections.ObjectModel.Collection1.get_Item(Int32 index)

请求的索引在列表查找中不存在。 Wagers 是一个数组,但 WagerType 没有请求的索引。 exception 是从列表的 get 语句中引发的。

关于c# - 索引超出范围错误,如果不是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15336998/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com