Cannot apply indexing with [] to an expression of type 'System.Collections.Generic.ICollection in mvc controller

前端 未结 3 799
悲哀的现实
悲哀的现实 2021-02-19 00:10
public ActionResult addstandardpackage1(ICollection SingleStay,ICollection DOUBLESTAY,ICollection TRIBLESTAY,ICollection FAMI         


        
3条回答
  •  抹茶落季
    2021-02-19 00:30

    Just convert it to an array:

    var s = SingleStay.ToArray();
    

    note that this will consume additional memory though.

    Better way would be to get an Array or any other collection-form that supports indexer in the first place.

    Yet another way would be to implement it with an index variable:

     var s = SingleStay;
     int i = 0;
     foreach (var cal in s)
     {
        //do your stuff (Note: if you use 'continue;' here increment i before)
        i++;
     }
    

提交回复
热议问题