How can I clean up this LINQ Query to use SelectMany in the sql syntax, instead of method chaining at the end like I have done?
 var runPeakWidths =
     (from ipa in runAnalysis.PassAnalyses
      let peakWidths = BuildPeakWidths(ipa)
      select peakWidths)
      .SelectMany(data => data);
Edit: Turned into a tight little method:
    public void CreateRunStatistics(Func<IPassAnalysis, IEnumerable<double>> buildMethod, string name)
    {
        var data = runAnalysis.PassAnalyses.SelectMany(buildMethod);
        statistics.Add(StatisticsBas开发者_StackOverflow中文版e.Calc(name, data));
    }
Thanks!
var runPeakWidths = runAnalysis.PassAnalyses.SelectMany(ipa => BuildPeakWidths(ipa));
You can also use this if you prefer:
var runPeakWidths = runAnalysis.PassAnalyses.SelectMany<Ipa, Pw>(BuildPeakWidths);
where Ipa is ipa's type
and Pw is PeakWidth's type.
I have been reliably informed (haven't verified myself) that return-type inference for method groups has now been implemented in the compiler, so this should work in C# 4:
var runPeakWidths = runAnalysis.PassAnalyses.SelectMany(BuildPeakWidths);
The SelectMany call can be avoided by nesting from clause in the query:
 var runPeakWidths =
      from ipa in runAnalysis.PassAnalyses
      from peakWidth in BuildPeakWidths(ipa)
      select peakWidth
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论