snetch
0
Q:

c# sort list

int[] arr = { 3, 6, 4, 1 };

// arr will be { 1, 3, 4, 6 }
Array.Sort(arr);

// arr will be { 6, 4, 3, 1 }
Array.Sort(arr);
Array.Reverse(arr);
5
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);
1
 int[] sortedCopy = from element in copyArray 
                    orderby element ascending select element;
1
using System;

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

New to Communities?

Join the community