Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sander van de Pas 74 posts 147 karma points
    Aug 20, 2012 @ 16:14
    Sander van de Pas
    0

    foreach with Where statement to check IsEven()

    Does somebody know the solution for a foreach loop for showing only the even (isEven()) items?

    Current code doesn't work:

    dynamic appItems = Model.Children;
    @foreach (dynamic c in appItems.Where("IsEven()"))
    { ... }
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Aug 20, 2012 @ 16:39
    Tom Fulton
    0

    Hi,

    I'm not sure there's a way to do this using IsEven - unless you loop through all the items and run a check inside the loop (ie is c.IsEven() { ... } ).

    There is a way you can do this in pure C# though (see this thread) if you use ChildrenAsList, something like this should work:

        var appItems = ((DynamicNode)Model).ChildrenAsList;
        foreach (var c in appItems.Where((x, c) => c % 2 == 1))
        {
        }

    HTH,
    Tom 

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies