In this blog post, I will be demonstrating how you can find the largest and smallest number in an array. Consider the following code snippet:
static void Main(string args)
List<int> list = new List<int>();
Console.WriteLine("Biggest element in the list is: " + list.Max());
Console.WriteLine("Smallest element in the list is: " + list.Min());
This code uses the Max and Min methods. The Collections class contains static utility methods that operate on collections like List, Set etc.
The Max() method returns the greatest element in the list according to the natural order or sorting.
Similarly, the Min() returns the smallest element in the list according to the natural order of sorting. When this code is executed, it will print the following output:
Leave a Comment