开发者

C# Lambda : using Event<T>()

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));开发者_Go百科

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));


Maybe you want something like this?

selectedElementArray.Cast<FrameworkElement>()
       .Where(fe => fe != parentElement)
       .ToList()
       .ForEach(fe => Canvas.SetTop(fe, top));

Or maybe:

foreach (var fe in selectedElementArray.Cast<FrameworkElement>()
                                       .Where(fe => fe != parentElement))
    Canvas.SetTop(fe, top);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜