Skip to content

Instantly share code, notes, and snippets.

@aggieben
Created July 1, 2013 20:56
Show Gist options
  • Select an option

  • Save aggieben/5904570 to your computer and use it in GitHub Desktop.

Select an option

Save aggieben/5904570 to your computer and use it in GitHub Desktop.
void Main()
{
// Write code to test your extensions here. Press F5 to compile and run.
}
public static class MyExtensions
{
// Write custom extension methods here. They will be available to all queries.
public static double Std(this IEnumerable<double> src)
{
var n = src.Count();
var avg = src.Average();
return Math.Sqrt(src.Aggregate(0D, (acc, k) => acc + Math.Pow(selector(k) - avg, 2)) / n);
}
public static double Std<TSource>(this IEnumerable<TSource> src, Func<TSource,double> selector)
{
return src.Select(selector).Std();
}
}
// You can also define non-static classes, enums, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment