Q:

C# program to find the smallest and largest elements of an array using predefined methods

belongs to collection: C# Basic Programs | array programs

0

C# program to find the smallest and largest elements of an array using predefined methods

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to find the smallest and largest elements of the array using predefine methods is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to find the smallest and largest 
//elements of an array using predefined methods.

using System;
using System.Linq;

class Sample
{
    static void Main()
    {
        int[] MyArray = { 40,30,20,10,50 };

        int large = MyArray.Max();
        int small = MyArray.Min();

        Console.WriteLine("Largest Element  : " + large);
        Console.WriteLine("Smallest Element : " + small);
    }
}

Output:

Largest Element  : 50
Smallest Element : 10
Press any key to continue . . .

Explanation:

In the above program, we created a class Sample that contains an array of integers.

int large = MyArray.Max();
int small = MyArray.Min();

In the above code, we find the largest and smallest elements from the array. Here we need to import "System.Linq" namespace into the program

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | array programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to find the sum of array elements using... >>
<< C# program to get the length of a jagged array usi...