Can I Create a Generic Method for Sum In C#
c#, generics
Solution
this operation already exists `Linq.Sum()`
var sum = new List<int>{1,2,3}.Sum();
Problem
Possible Duplicate: Generics - where T is a number? I have created a generic method for maximum and I use `IComparable` interface Does anybody know how can I create a generic method for Sum? Which interface is useful in this method? Here is my code for GetMax: ``` public static T GetMax<T>(T[] array) where T : IComparable { T min = array[0]; foreach (T item in array) { if (min.CompareTo(item) < 0) { min = item; } } return min; } ```