Generalized method for finding the maximum in an array

C# Easy generics

Task «Generalized method for finding the maximum in an array»

Implement a generic method Max<T> that takes an array of elements of type T and returns the maximum element. The type T must implement the IComparable<T> interface. If the array is empty, the method should return default(T). Input data: first an integer N (size of the array), then N elements of the same type (int or double). It is guaranteed that all elements are of the same type.

Input Format

Integer N, then N numbers (int or double).

Output Format

Maximum value among the entered numbers, or 'null' (string), if the array is empty.

Examples

Example 1

INPUT
5 3 7 1 9 4
OUTPUT
9

Example 2

INPUT
0
OUTPUT
null

Example 3

INPUT
3 2.5 1.1 3.8
OUTPUT
3.8

Example 4

INPUT
5.0 4.0 6.0 3.0 4.0 5.0
OUTPUT
78.54 31.42 24.00 20.00 6.00 12.00
main.cs