Julius Julius - 1 month ago 4x
C# Question

C# Orderby int linq

Hi I am trying order my type using this code in a method:

ApplicationServices.Prime_Material.OrderBy(x => x.Code).ToList();

But after ejecute it the type still the same, I was Reading about use .Sort but this is not a list then I can not use it.

this is the code of the type:

public class Prime_Material : BindableBase
private int _Code;
public int Code
get { return _Code; }
set { SetProperty(ref _Code, value); }

private string _Name;
public string Name
get { return _Name; }
set { SetProperty(ref _Name, value); }

public class Values_Prime_Material : ObservableCollection<Prime_Material> { }

public static class ApplicationServices
public static Values_Prime_Material Prime_Material = new Values_Prime_Material();

static ApplicationServices()

Any help is appreciated.


Your code does not modify the original ApplicationServices.Prime_Material; rather it returns the newly ordered list. Thus you should create a variable to collect the returned list. Like this:

var orderedList = ApplicationServices.Prime_Material.OrderBy(x => x.Code).ToList();
//use "orderedList" henceforth wherever you need an ordered list