问题描述
我在变量"selectedElementArray"中有一个 FrameworkElements 的 ArrayList
下面的代码用于将控件对齐到顶部
double top = 100; selectedElementArray.Cast<FrameworkElement>() .ToList() .ForEach(fe => Canvas.SetTop(fe, top));
这工作正常.
但我需要避免一个 FrameworkElement,比如 parentElement,它存在于"selectedElementArray"中
selectedElementArray.Cast<FrameworkElement>() .ToList() .Except(parentElement) .ToList() .ForEach(fe => Canvas.SetTop(fe, top));
我尝试使用"除外".但抛出一些异常.
请帮忙....
比尼尔
推荐答案
你只需要一个 where 子句.
selectedElementArray.Cast<FrameworkElement>() .Where(element => element != parentElement) .ToList() .ForEach(fe => Canvas.SetTop(fe, top));
要使用except,你需要传递一个IEnumerable:
selectedElementArray.Cast<FrameworkElement>() .Except(new FrameworkElement[]{ parentElement }) .ToList() .ForEach(fe => Canvas.SetTop(fe, top));
问题描述
I have an ArrayList of FrameworkElements in variable "selectedElementArray"
and the below code is used to align controls to top
double top = 100; selectedElementArray.Cast<FrameworkElement>() .ToList() .ForEach(fe => Canvas.SetTop(fe, top));
this is working fine.
but i need to avoid a FrameworkElement, say parentElement, which exists in "selectedElementArray"
selectedElementArray.Cast<FrameworkElement>() .ToList() .Except(parentElement) .ToList() .ForEach(fe => Canvas.SetTop(fe, top));
i tried using "Except". but throwing some exception.
pls help....
Binil
推荐答案
You just need a where clause.
selectedElementArray.Cast<FrameworkElement>() .Where(element => element != parentElement) .ToList() .ForEach(fe => Canvas.SetTop(fe, top));
To use except, you need to pass an IEnumerable:
selectedElementArray.Cast<FrameworkElement>() .Except(new FrameworkElement[]{ parentElement }) .ToList() .ForEach(fe => Canvas.SetTop(fe, top));
相关问答
onblur()event for a textbox in c#
在C#中使用icomparer <t> .compare(t,t)
href onclick event with stringbuilder in c#
为什么在C#中使用tast <t> <t> <t>?
c# com interop dll/ vb6 project-event doesn't fire
"errorMessage": lambda函数中的 "event is not defined"。
C# - 找到两个List<T>s的共同成员 - Lambda语法
C#中的lambda函数
使用c# lambda的n个数字的阶乘...?
C#使用通用类型查询lambda查询
相关标签/搜索