How can I clear this LINQ query (SelectMany)?

How can I clear this LINQ query to use SelectMany in sql syntax instead of the method chain at the end, how did I do it?

 var runPeakWidths =
     (from ipa in runAnalysis.PassAnalyses
      let peakWidths = BuildPeakWidths(ipa)
      select peakWidths)
      .SelectMany(data => data);

Edit: It turned out to be hard:

    public void CreateRunStatistics(Func<IPassAnalysis, IEnumerable<double>> buildMethod, string name)
    {
        var data = runAnalysis.PassAnalyses.SelectMany(buildMethod);
        statistics.Add(StatisticsBase.Calc(name, data));
    }

Thank!

+3
source share
2 answers
var runPeakWidths = runAnalysis.PassAnalyses.SelectMany(ipa => BuildPeakWidths(ipa));

You can also use this if you want:

var runPeakWidths = runAnalysis.PassAnalyses.SelectMany<Ipa, Pw>(BuildPeakWidths);

where Ipa- type Ipa and Pw- type PeakWidth.

I was reliably informed (I have not confirmed myself yet) that the return-type method for method groups is now implemented in the compiler, so this should work in C # 4:

var runPeakWidths = runAnalysis.PassAnalyses.SelectMany(BuildPeakWidths);
+5
source

The call SelectManycan be avoided by enclosing a fromsentence in the request :

 var runPeakWidths =
      from ipa in runAnalysis.PassAnalyses
      from peakWidth in BuildPeakWidths(ipa)
      select peakWidth
+4
source

Source: https://habr.com/ru/post/1763239/


All Articles