
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# program to find Largest, Smallest, Second Largest, Second Smallest in a List
Set the list
var val = new int[] { 99, 35, 26, 87 };
Now get the largest number.
val.Max(z => z);
Smallest number
val.Min(z => z);
Second largest number
val.OrderByDescending(z => z).Skip(1).First();
Second smallest number
val.OrderBy(z => z).Skip(1).First();
The following is the code −
Example
using System; using System.Linq; public class Program { public static void Main() { var val = new int[] { 99, 35, 26, 87 }; var maxNum = val.Max(z => z); Console.WriteLine("Maximum Number: " + maxNum); var minNum = val.Min(z => z); Console.WriteLine("Minimum Number: " + minNum); var secondMax = val.OrderByDescending(z => z).Skip(1).First(); Console.WriteLine("Second Largest Number: " + secondMax); var secondMin = val.OrderBy(z => z).Skip(1).First(); Console.WriteLine("Second Smallest Number: " + secondMin); } }
Output
Maximum Number: 99 Minimum Number: 26 Second Largest Number: 87 Second Smallest Number: 35
- Related Articles
- Python program to find Largest, Smallest, Second Largest, and Second Smallest in a List?
- Java program to find Largest, Smallest, Second Largest, Second Smallest in an array
- C program to find the second largest and smallest numbers in an array
- C++ program to find Second Smallest Element in a Linked List
- Python program to find the second largest number in a list
- Python Program to Find the Second Largest Number in a List Using Bubble Sort
- Find the Second Largest Element in a Linked List in C++
- Program to find second largest digit in a string using Python
- C# Program to get the smallest and largest element from a list
- Program to find Smallest and Largest Word in a String in C++
- Rearrange An Array In Order – Smallest, Largest, 2nd Smallest, 2nd Largest,. Using C++
- Find smallest and largest elements in singly linked list in C++
- Find the smallest and second smallest elements in an array in C++
- Maximum sum of smallest and second smallest in an array in C++ Program
- C++ Program to find the second largest element from the array

Advertisements