我正面临着一个奇怪的问题,我没有用过太多的c#编程,而且最近才开始编程,所以如果这个问题实际上只是一个初学者的错误,我提前道歉。
int i = 0;
var index = from x in (
from v in Category.Items
select new { Key = i++, Value = v })
where ((MenuCategory) x.Value).id == menuItems[items.SelectedIndex].category
select x.Key;我正在尝试获取Category.Items[] (其中的字段id是特定值menuItems[items.SelectedIndex].category)中特定对象的索引
发布于 2017-02-07 21:53:55
LINQ查询不应该引起这样的副作用。你可以通过方法语法和Select的重载得到你想要的东西
var selectedCatId = menuItems[items.SelectedIndex].category;
var indexes = Category.Items
.Select((c, index) => new { Key = index, Value = c })
.Where(x => ((MenuCategory)x.Value).id == selectedCatId)
.Select(x => x.Key);https://stackoverflow.com/questions/42091474
复制相似问题