public ActionResult addstandardpackage1(ICollection<int> SingleStay,ICollection<int> DOUBLESTAY,ICollection<int> TRIBLESTAY,ICollection<int> FAMILYSTAY,ICollection<int> EXTRABED)
{
var s = SingleStay;
for (int i = 0; i < SingleStay.Count; i++ )
{
var cal = SingleStay[i];
}
foreach (var key in SingleStay)
{
var value = key;
}
}
在 for 循环中,我收到类似 Cannot apply indexing with [] to an expression of type 但我需要在 for 循环中,在 for every i am getting 中的错误。因为基于 for 循环,我会将详细信息与其他集合列表绑定。请帮我。
我收到错误var cal=Singlestay[i]
.
ICollection
不暴露indexer
。您有三个选择:
- Change
ICollection
to IList
- Use
ElementAt
这是继承自IEnumerable
。但请注意 - 它不可能有效。
- 评估传递集合到列表(
ToList()
)
收藏 http://msdn.microsoft.com/en-us/library/92t2ye13.aspx(及其公开的方法)在 msdn 上。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)