c# how to sort a list

var simpleList = new List<ObjectName>();
// Order by a property
list.OrderBy(o => o.PropertyName);
// Order by multiple property
list.OrderBy(o => o.PropertyName).ThenBy(o => o.AnotherProperty);
// Same but descending
list.OrderByDescending(o => o.PropertyName).ThenByDescending(o => o.AnotherProperty);

5
4
Awgiedawgie 440220 points

                                    using System;

class Program
{
    static void Main()
    {
        string[] colors = new string[]
        {
            &quot;orange&quot;,
            &quot;blue&quot;,
            &quot;yellow&quot;,
            &quot;aqua&quot;,
            &quot;red&quot;
        };
        // Call Array.Sort method.
        Array.Sort(colors);
        foreach (string color in colors)
        {
            Console.WriteLine(color);
        }
    }
}

5 (4 Votes)
0
4.44
9
Awgiedawgie 440220 points

                                    using System.Linq;

//sorts in acending order {1,2,3,4,5}
myList.Sort();

//Sorts in decending order {5,4,3,2,1}
myList.Sort();
myList.Reverse();

//to sort a custom list of classes you have to 
//add this inside of your class
public int CompareTo(MyClass other)//replace MyClass with your class type
{
    //replace varInClass to the variable that you would like to compare
	return this.totalScore.CompareTo(other.varInClass)
}

4.44 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
list . sort C# List Sort +C# write sort function the string list in c# list sort c# unioty sort the string list in c# how to use list sort number C# how to use list sort C# how to us list sort C# csharp list sort by c# ordering a list by Ascending c# list orderby ascending c# list order by ascending check list sort or ascending c# sort items from list in c# Sorting alist in C# code inside list.sort c# what do list.sort have c# list sort code c# sort a list ascending c# list sort c# string sort function for list in c# orderby list c# orderby C# can I order a list sort a int list in c# c# order a list sortring a list in c# c# list sort docs list int sort c# sortable list c# c# orderby list Sort on list of object c# order list c# order by sort list string c# sort list of objects in c# c# list string sort list sort c# code c# sort items in list sort list with list objects c# sort list int c# c# sort list strings sort list in csharp c# order list in list c# list order by in list sort 1 list c# list sorting c# c# int list sort how to sort a list based another list in c# c# list sort by id object list sort c# sorting list of objects in c# How to sort by name in a list C# how to sort data from list inside list c# how to sort data from list of list in c# how to sort list about list in c# c# list sort ascending arraylist.orderby c# sorter order by list c# asc how to sort an array list in c# how to sort a specified item in list c# how to order a list with the orderby in c# how to order elements in a list with orderby c# sort list using compareTo c# custom list sort c# c# sorl list by order Array.Sort on list c# create sorted list c# how to sort an array list c# c# sort int list sort list c# compareTo list sort custom C# sort by value list c# c# To sorted list how to sort an arraylist in c# sorting a sorted list c# sorted list sort c# method to sort list items in ascending order c# sort elements of list c# how to use list.Order by c# how to sort a list in ascending order c# sort out list c# how to order list in c# sort in a list in c# how to sort Array[] list in c# sorted list in c# orderby list c# sorting elements in list c# sorting methods c# c# sort class list sort list numerically c# sorted list c# example sort list by number c# sort List of type in c# string list sort c# sort in list c# sorting list method c# sort list c# int c# sort numbers in a list c# order list items c# list with order how to sort in list in c# does .sort work on list and arrays c# does .sort work on list c# c# sort list by value c# sort items in listbox sort string list c# c# sort enyumerable list sort list by item name c# sort list by certain element c# How to sort the list in c#? c# list.orderby sort c# list by how to list.Sort c# can you sort list using result of methd c# can you sort list OrderBy using result of methd c# c# list that does not sort c# sortby list get order from list c# c# sort list by id sorting of list in c# c# order list of objects sort int list c# method to sort list c# how to sort a list in class c# sort method for list in c# how to sort elements in list in c# sorting list of a list C# sort list of list in c# sorting list of list c# c# how to order a list list order by in c# s# list sort list c# sort example using list.sort c# List sort by a key in c# c# sort list of objects int list sort c# c# sorting list of objects c# sort ascending list how to order by a list in c# c# orderby on list list order ascending c# list.order C# sorted list example in c# c# list sorting c# sort string list c# list.sort example number sort c# list How to use OrderBy in C# list c# sortings array sort object list in c# orderby function List in c# c# sort number list sort list given sort order c# c# list order by function c# list sort object c# list sort increasing arrange order in list C# how to sort a list of objects in c# c# sort a List by order ascending order list c# list to sorted list c# c# list sort function example how to sort list string in c# c# sort an IList c# sort custom list c# struct list sort sorting in list c# orderby in list c# sorting c# sort list in ascending order c# sorted list c# sort list using icomparer c# how to order a list in c# how to sort a list according to another list in c# how to sort a list a list in c# list.OrderBy c# c# list sort by code example sorted list c# how to sort a list in ascending order in c# how to sort data using name in list c# c# sorting methods c# sort list from high to low set default compararer List.Sort() C# List.Sort() C# sort list ion c# how to sort list ascending c# sorting list in c# c# list sort by value how to sort a list of int in c# how to sort a list of struct in c# how to use sort function of list in c# c# sort arraylist C# ohjelmointi list sort order list c# orderby c# list how to sort list c# list&lt;&gt; list.sort c# c# sort list in ascending order list sort c# thenBy sort in list in c# c# sort list into new list c# method to order a list sorting in c# c# list order c# list sort after ordered list c# orderby list order by c# c# sorted list by value sort object list c# c# list.sort moethod c# list int sort how to order a list of objects in c# c# sort list by name list order by c# sorting algorithms c# sort list example sortedlist c# order a list c# list sort c# example array sort c# vs list sort sort list c# ascending c# sorting help c# how to sort list C# orderdy list list orderby c# sort list c sharp sort C# string list sort list c# with sort c# list orderby c# sort a list in ascending order how to sort list of objects in c# list sorted c# sort list by OrderBy in c# sorting arraylist in c# c# sort list string sort list desnding c# order by list c# order by in list c# c# sorted list list.orderby in c# c# ordernar list sort items from list c# how to sort a list of objects C# order ascending list c# c# 2d list c# map list c# list object sort sort list c# by how to manually sort a list in c# how to sort a list in c# comparison c# sort c# list sort descending list where display particular value order using c# generic sorting c# list how to sort an array in c# sort method C# List Sort item1 arraylist sort() c# c# linq sort list descending sorting numbers in c# sort list by object properties c# order by generic list c# list comparer c# c# sort methods sort list values in c# c# List IsSort comparison sort in c# order list in c# how sort a list c# c# list sorted c3 list sorting c# sort list by function c# sort comparator c# list sort string c# sort list algorithm c# how to soer a list order a list by value c# how to sort a list depending on a value of the object c# c# sort list by property order in list c# c# list sort ascending order by attribute of item Sort(Comparison&lt;T&gt;) object c# list built in sort c# ordenar list organize list by value c# c# order list by value ordered list c# c3 sort list sorting c# sort list of ints c# linq sort list by property list sort c# algorithm .sort() c# list rearrange the list in c# by value c# sort list with custom comparer c# sort in list sort generic list c# arraylist sort c# c# how to order list c# using sort sort list by name c# how to sort an array in c sharp sorting a list by compare c# ordering list c# sort list by value c# ordering a list in c# how to sort the list in c# c# .sort list sort data in list c# asp.net core order of list by Sort the collection in list c# C# order list by string C# list sort using Sorting elements c# c# list sorted by value .net sort list list sort string c# sort the list c# sort list item in c# asp.net sort list of items from greatest to lowest how to use order or sort by in list using c# .sort() c# sort a generic list in c# c# list order elements c# string list sort order a list of a list c' .net core sort list list sort example c# sort console c# c# sort list objects c# sort example c# sort list t by property c# list.sort() how to sort the list items in c# c# create sorting sorting in c# list sort elements from class in c# sort list based on integer in string c# sort method list c# c# sort list by class value list&lt;string&gt; is not Sorted c# c# sort list of strings arrange list c# order object list c# c# list class sort sort a list of object in c# sort in a list of object in c# c# order list by property lists sort in c# c# order list by list of names c# sort class by property c# class properties orderby how to sort list by value C# list sort by property c# void function list sort c# c# sort a list of objects c# sort list by change sorting list c# change sorting list on c# C# sort by id sample order a list based on value c# order list by value c# list sort method c# c# are list by order? c# sorting sort a list in c# List&lt;string&gt; .Sort c# c# list of string sort C# sort using list c# sort c# list sort IComparer&lt;T&gt; sort c# list how to sort using lists in c# c# sort list simple example c# sort a csharp sort list sort list by property c# sort method on list c# c# sorting a list .sort c# sort list in c# sorting list c# list.sort in c# c# sort using predicate List data sort in c# sort c# list simple list sort c# object c# list order by how to order list c# C# parameter type sortable list c# sortieren c# .sort sorting a list in c# sortin g a list by balue c# c# reorder list c# list sort by name c# Sort List c# Sorts List sort list type c# c# sort by c# sorting list sort a list x# how to sort list in c# list sort in c# sort list python c# how to sort a list c# sort() how to sort a list c# list.sort c# how is workijg list.sort() c# works list.sort() c# sort a list c# c# list.sort sort in c# c# order list c# sort function order list by property C# c# sort c sharp list sort C# list sort by sorting a list c# c# sort a list sort function C# list.sort c# sort c# list sort c# list sort c# sort list c# c# list sort c# sort list
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source