#Does C# IEnumerable have any
1 messages · Page 1 of 1 (latest)
I just wrote up an implementation of ArgMax, though I don't recall the right way to generalize a Comparable in this version of C#:
public static T ArgMax(IEnumerable<T> enumerable, Func<T, float> func) {
float maxVal = Mathf.NegativeInfinity;
T maxArg = enumerable.First();
foreach (T t in enumerable) {
float val = func(t);
if (val > maxVal) {
maxArg = t;
maxVal = val;
}
}
return maxArg;
}
this would be the IEnumerable.MaxBy method, which is sadly not available in unity's C# version.
you can always grab the actual implementation from source.dot.net and drop it into your project (with a bit of modification to make it work, but it's easy enough). or if you prefer yours you can just keep that 🤷♂️
Why is Unity so behind with C# versions? Is it just that it's a big lift to upgrade?