Question: I have class like:

```
class SortNode
{
    public Int32 m_valRating = 0;

    public SortNode(Int32 valRating)
    {
        this.m_valRating = valRating;
    }
}

```

and some list `refSortNodeList`:

```
List<SortNode> refSortNodeList = new List<SortNode>();

Random refRandom = new Random();

for (int i = 0; i < 100; ++i)
{
    refSortNodeList.Add(new SortNode(refRandom.Next(-10, 30)));
}

foreach (var varSortNode in refSortNodeList)
{
    Console.WriteLine("SortNode rating is {0}", varSortNode.m_valRating);
}

```

How to sort easily my `refSortNodeList` by `m_valRating` field? Or maybe I need to use some another `List` class?

Answer: 
Use Linq order by. 

```
var mySortedList = refSortNodeList.OrderBy(x => x.m_valRating);

```

Here is a real live example where I am pulling a list from a database but it is exactly the same concept. 

```
 vendorProducts = (from vp in db.COMPANIES_VND_PRODUCTS
                    join p in db.CT_CT_INV_CLASSES on vp.CLASS_ID equals p.CLASS_ID
                    join m in db.CT_CT_MODALITY_CODES on vp.MODALITY_ID equals m.MODALITY_ID
                    where vp.COMPANY_ID == companyId
                    select new ProductTypeModality
                    {
                      Active = p.ACTIVE.Equals("Y") ? true : false,
                      BioMedImaging = p.BIOMED_IMAGING,
                      Code = p.CLASS_CODE,
                      Description = p.DESCRIPTION,
                      Id = p.CLASS_ID,
                      PricingMargin = p.PRICING_MARGIN,
                      ModalityCode = m.MODALITY_CODE,
                      ModalityId = m.MODALITY_ID,
                      VendorId = companyId
                    }).OrderBy(x => x.Code).ToList<ProductTypeModality>();

```
It's easy using linq:

```
var newlist = refSortNodeList.sort( n => n.m_valRating );

```