我确信这可以通过Linq轻松完成,但我无法弄清楚.
var ls1 = plotter.Model.Series.FirstOrDefault(x => x.IsSelected);
var ls2 = plotter.Model.Series.FirstOrDefault((x => x.IsSelected)&&(ls2!=ls1));
Run Code Online (Sandbox Code Playgroud)
我假装要做的是获取属性IsSelected设置为true 的两个第一个对象.
我不能使用上面写的语法,因为编译器ls2在声明之前不能使用"局部变量".
使用Where仅筛选所选结果,然后使用Take选择前两个例如
plotter.Model.Series.Where(x => x.IsSelected).Take(2);
Run Code Online (Sandbox Code Playgroud)