AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
EnumerableExtensions.cs
Go to the documentation of this file.
1 // Licensed under the MIT License. See LICENSE in the project root for license information.
2 
3 using System;
4 using System.Collections.Generic;
5 
6 namespace HoloToolkit.Unity
7 {
8  public static class EnumerableExtensions
9  {
14  public static T MaxOrDefault<T>(this IEnumerable<T> items, IComparer<T> comparer = null)
15  {
16  if (items == null) { throw new ArgumentNullException("items"); }
17  comparer = comparer ?? Comparer<T>.Default;
18 
19  using (var enumerator = items.GetEnumerator())
20  {
21  if (!enumerator.MoveNext())
22  {
23  return default(T);
24  }
25 
26  var max = enumerator.Current;
27  while (enumerator.MoveNext())
28  {
29  if (comparer.Compare(max, enumerator.Current) < 0)
30  {
31  max = enumerator.Current;
32  }
33  }
34  return max;
35  }
36  }
37  }
38 }