Index (zero based) must be greater than or equal to zero

后端 未结 8 885
灰色年华
灰色年华 2020-12-01 08:32

Hey I keep getting an error:

Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

8条回答
  •  攒了一身酷
    2020-12-01 09:23

    This can also happen when trying to throw an ArgumentException where you inadvertently call the ArgumentException constructor overload

    public static void Dostuff(Foo bar)
    {
    
       // this works
       throw new ArgumentException(String.Format("Could not find {0}", bar.SomeStringProperty));
    
       //this gives the error
       throw new ArgumentException(String.Format("Could not find {0}"), bar.SomeStringProperty);
    
    }
    

提交回复
热议问题