public int Compare_Absolute_Tests(int a, int b, int c, int d, int e) { Func <int, int, int> absoluteComparerFunc = (x, y) => { if (Math.Abs(x) > Math.Abs(y)) { return(1); } if (Math.Abs(x) < Math.Abs(y)) { return(-1); } return(0); }; var list = new[] { a, b, c, d, e }; var sortedList = list.OrderBy(z => z, ComparerFunc <int> .Create(absoluteComparerFunc)) .ToList(); return(sortedList.Last()); }
public string Compare_OrderBy_Tests(int a, int b, int c, int d, int e) { Func <int, int, int> evensFirst = (x, y) => { if (x == y) { return(0); } if (x % 2 == y % 2) { return(x < y ? -1 : 1); } return((x % 2 == 0) ? -1 : 1); }; var list = new[] { a, b, c, d, e }; var sortedList = list.OrderBy(z => z, ComparerFunc <int> .Create(evensFirst)) .ToList(); return(string.Join(",", sortedList.Select(x => x.ToString()))); }