none
Let binding inside Aggregate function RRS feed

  • Question

  • Hi

    Is it possible to make let bindings inside the LINQ aggregate function?

    I.e. myList.Aggregate("", (current,elem) => let......)

    Monday, July 15, 2013 9:56 AM

Answers

  • Hi JensFogh,

    It is not very clear to me what you want.

    According to the documentation, it will work if you can return a type of TAccumulate for the "Func<TAccumulate, TSource, TAccumulate> func" parameter.

    Since there is no examples in your post, I'm not sure what is exactly the problem in your scenario. Here is an example returns all words contains 'a', 'o', or 'e'.

    string[] strings = {"at", "test", "auto", "an", "in", "on", "off", "un"};
    string[] test = {"a o", "e"};
    string numEven = strings.Aggregate("", (result, next) =>
                                            (from t in test
                                             let characters = t.Split(' ')
                                             from c in characters
                                             select c
                                            )
                                            .Any(c => next.Contains(c)) ? result + " " + next : result);
    Best regards,

    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help


    Wednesday, July 17, 2013 9:52 AM
    Moderator