Skip to content

Instantly share code, notes, and snippets.

@lopespm
Last active May 30, 2017 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lopespm/2cedae5a902c978342a3a48d2f928b9a to your computer and use it in GitHub Desktop.
Save lopespm/2cedae5a902c978342a3a48d2f928b9a to your computer and use it in GitHub Desktop.
MidRange Enumerable Extension (C# LINQ)
using System.Collections.Generic;
using System.Linq;
static class EnumerableExtensions
{
/// <summary>
/// Calculate the enumerable's mid-range https://en.wikipedia.org/wiki/Mid-range
/// </summary>
public static float MidRange(this IEnumerable<float> source)
{
return (source.Min() + source.Max()) / 2.0f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment