使用 antDesign blazor 时,@for语句嵌套<Radio 循环异常问题索引溢出问题

在使用antDesign blazor 时

@code{
       string[]  选项list ="张三,李四".Split(',');
}
    <RadioGroup @bind-Value="@radioValue">
    @for(int i=0;i<选项list.Count();i++)
    {
        <Radio Value="@i">@选项list[i]</Radio>  //这个位置总报  索引超出范围
    }

    </RadioGroup>
   

img


如上代码,在运行时总报 ”System.IndexOutOfRangeException:“Index was outside the bounds of the array.”"
我单步执行了一下,竟然出现循环完成后又再次执行了 Radio 语句
无法理解

我想要达到的结果

我的代码错在哪里?

找到原因了
https://docs.microsoft.com/zh-cn/aspnet/core/blazor/components/?view=aspnetcore-6.0&WT.mc_id=DT-MVP-5003987#child-content

img


改成下面就可以了

 <RadioGroup @bind-Value="@radioValue">
    @for(int i=0;i<选项list.Length;i++)
    {
       var index=i; 
        <Radio Value="@index">@选项list[index]</Radio>  //这个位置总报  索引超出范围

    }
    </RadioGroup>

不是能直接绑定吗?

<RadioGroup Options="@选项list" @bind-Value="radioValue"></RadioGroup>

改Length属性试试

@for(int i=0;i<选项list.Length;i++)