Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# list sort by property string

var sortedQuery = sampleList.OrderBy(x => x.MyProperty);
Comment

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);
Comment

c# sort array of objects


public class People
{
	public string FirstName;
  	public String LastName;
  
  	public Person(string firstName,string lastName)
    {
    	FirstName = firstName;
      	LastName = lastName;
    }
  
  public static void Main(string args[])
  {
  	Person[] people = {
    new Person(){ FirstName="Steve", LastName="Jobs"},
    new Person(){ FirstName="Bill", LastName="Gates"},
    new Person(){ FirstName="Lary", LastName="Page"}
};
 
Array.Sort(people);
    
  }
	
}

Comment

sorting a list of objects in c#

List<Order> SortedList = objListOrder.OrderBy(o=>o.OrderDate).ToList();
List<Order> DescSortedList = objListOrder.OrderByDescending(o=>o.OrderDate).ToList();
Comment

list sort c#

List<Order> SortedList = objListOrder.OrderBy(o=>o.OrderDate).ToList();
Comment

c# list sort by property string

list.Sort((a, b) =>  a.StringProperty.CompareTo(b.StringProperty));
Comment

C# sort list<>

var users = new List<User>();
users.Add(new User("John", "Doe", 1230));
users.Add(new User("Lucy", "Novak", 670));
users.Add(new User("Ben", "Walter", 2050));
users.Add(new User("Robin", "Brown", 2300));
users.Add(new User("Amy", "Doe", 1250));
users.Add(new User("Joe", "Draker", 1190));
users.Add(new User("Janet", "Doe", 980));
users.Add(new User("Albert", "Novak", 1930));
users.Sort((u1, u2) =>
{
    int result = u1.LastName.CompareTo(u2.LastName);
    return result == 0 ? u1.Salary.CompareTo(u2.Salary) : result;
});
Comment

PREVIOUS NEXT
Code Example
Csharp :: convert excel to datatable without xml configuration 
Csharp :: c# use cefcharp and selenium can? 
Csharp :: How to scroll to bottom of ListBox 
Csharp :: ENUM error codes all 
Csharp :: c# interoperability with linux or bash script 
Csharp :: Enviar correos en C# con MailKit 
Csharp :: IOS app crashing on ios 15 unity 
Csharp :: c# get buttons row and column in grid 
Csharp :: how to take previous record in linq c# 
Csharp :: netmath 
Csharp :: OOP inC# 
Csharp :: DefaultContractResolver .net exclude null values JsonSerializerSettings ContractResolver DefaultContractResolver 
Csharp :: stack iterator c# 
Csharp :: unity remove all child 
Csharp :: replace bar c# 
Csharp :: How to solve error in ExecuteNonQuery() in asp.net 
Csharp :: tulpep notification window example c# 
Csharp :: unity run all interfaces 
Csharp :: in model add to give drop down message 
Csharp :: c# check file similarities 
Csharp :: How to retrieve a dead letter msg dotnet 
Csharp :: grab reference from method parameter c# 
Csharp :: sort number in dynamo 
Csharp :: how to create more accurate searching c# 
Csharp :: unity variable in editor limit value 
Csharp :: EF will not create columns RULE 
Csharp :: c# xaml textblock new line 
Csharp :: how to split a string in f# 
Csharp :: Make a variable public without showing in the inspector 
Csharp :: c# return default "" if null 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =