C# Program to Sort a List of Integers Using the LINQ OrderBy() Method Last Updated : 06 Dec, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a list of integers, now our task is to sort the given list of integers. So we use the OrderBy() method of LINQ. This method is used to sort the elements in the collection in ascending order. This method is overloaded in two different ways: OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>): It is used to sort the items of the given sequence in ascending order according to the key and performs a stable sort on the given sequence or list.OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>, IComparer<TKey>): It is used to sort the items of the given sequence in ascending order by using a given comparer and also performs a stable sort on the given sequence.Example: Input : [90, 87, 34, 23, 22, 56, 21, 89] Output : [21, 22, 23, 34, 56, 87, 89, 90] Input : [10, 11, 2, 3, 18, 5,] Output : [2, 3, 5, 10, 11, 18] Approach: 1. Create and initialize a list of integer types. For example nums. 2. Sorting the list(named nums) using OrderBy() method var result_set = nums.OrderBy(num => num);3. Display the result using the foreach loop. Example: C# // C# program to sort a list of integers // Using OrderBy() method using System; using System.Linq; using System.Collections.Generic; class GFG{ static void Main(string[] args) { // Creating and initializing list of integers List<int> nums = new List<int>() { 50, 20, 40, 60, 33, 70 }; // Using order by method we sort the list var result_set = nums.OrderBy(num => num); // Display the list Console.WriteLine("Sorted in Ascending order:"); foreach (int value in result_set) { Console.Write(value + " "); } } } OutputSorted in Ascending order: 20 33 40 50 60 70 Comment More infoAdvertise with us Next Article C# Program to Sort a List of Employees Based on Salary using LINQ P pulamolusaimohan Follow Improve Article Tags : C# C# Programs CSharp LINQ Similar Reads C# Program to Sort a List of String Names Using the LINQ OrderBy() Method Given a list of string names, now our task is to sort the names given in the list using the OrderBy() method of LINQ. This method is used to sort the elements in the collection in ascending order. While using this method in the LINQ query you don't need to add an extra condition to sort the list in 2 min read C# Program to Find Integer Numbers from the List of Objects and Sort them Using LINQ Given a list of objects, we need to find the integer double numbers from the list of objects and sort them using LINQ. So this task can be done using the OfType() method and then the sorting of numbers can be done by using OrderBy() method. Let discuss them one by one along with their syntax: 1. OfT 2 min read C# Program to Sort Student Names in Descending Order using LINQ Given a list of student names, now our task is to sort the names given in the list in descending order using the LINQ, This task can be done using OrderByDescending() method of LINQ. This method is used to sort the elements in the collection in descending order. While using this method in the LINQ q 2 min read C# Program to Demonstrate the Example of LINQ Intersect() Method with OrderBy() Method LINQ is known as Language Integrated Query and it is introduced in .NET 3.5. It provides the power to .NET languages to create queries to retrieve data from the data source. In this article we will demonstrate the example of the LINQ intersect() method with OrderBy() method. 1. intersect() Method: T 3 min read C# Program to Sort a List of Employees Based on Salary using LINQ Given a list of employees, now we sort the list of employees according to their salary using LINQ. So to this task, we use the OrderBy() method. This method is used to sort the elements of the specified sequence in ascending order. Example: Input: {id = 101, Name = Rohit, Salary = 50000, Department 3 min read C# Program to Find the Index of Even Numbers using LINQ Given an array, now our task is to find the index value of the even numbers present in the given array using LINQ. LINQ is known as Language Integrated Query and was introduced in .NET 3.5. It gives the power to .NET languages to generate queries to retrieve data from the data source. So to do this 2 min read Like