2021年4月10日星期六

How do I make a method like .Sum() or .Average() that can take an argument lambda expression

How do I make a method like .Sum() or .Average() that work by themselves as an extension method but also able to do .Sum(x => x.Value).

I'm thinking it will probably require an overload but maybe there's a way with an optional parameter.

Here's what my current extension method looks like:

public static double StdDev(this IEnumerable<double> values)  {      //code  }  

I'm just not quite sure where to go from here.

https://stackoverflow.com/questions/67040579/how-do-i-make-a-method-like-sum-or-average-that-can-take-an-argument-lambd April 11, 2021 at 09:03AM

没有评论:

发表评论