Use ThenBy() in Linq Query.

We want to use ThenBy()  in Linq Query. How to use this please help me.
Last updated:3/21/2016 10:33:36 PM

1 Answers

Aditya Patel
Aditya Patel

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Prototype

{

class Example

{

static void Main()

{

IList<employee> List = new List<employee>() {

new employee() { id = 1, empname = 'John', age = 18 } ,

new employee() { id = 2, empname = 'Steve', age = 15 } ,

new employee() { id = 3, empname = 'Bill', age = 25 } ,

new employee() { id = 4, empname = 'Ram' , age = 20 } ,

new employee() { id = 5, empname = 'Ron' , age = 19 },

new employee() { id = 6, empname = 'Ram' , age = 18 }

};

var thenByResult = List.OrderBy(s => s.empname).ThenBy(s => s.age);

foreach (employee emp in thenByResult)

Console.WriteLine('Id:' + emp.id + ', Name:' + emp.empname + ', Age:' + emp.age);

Console.ReadLine();

}

}

class employee

{

public int id { get; set; }

public string empname { get; set; }

public int age { get; set; }

}

}

Answer