我有这段代码:
var cat = solutions
.Descendants("Solution")
.Select(x => new
{
ID = (string)x.Element("ID"),
Properties = x.Elements("Property").Select(p => new
{
Name = (string) p.Element("Name"),
Value = (string) p.Element("Value"),
idx = i++
})
.Where(y => indexesToChoose.Contains(y.idx))
.OrderBy(z => indexesToChoose.FindIndex(p => p == z.idx))
.ToList()
});
我只想让它数到 11,然后重置为 0 重新开始,例如它会读取 8,9,10,11,0,1 等。
最佳答案
最简单的方法是使用模数:
idx = i++ % 12
关于c# - 达到目标时如何重置计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31079658/