Skip to content

Instantly share code, notes, and snippets.

View meSailesh's full-sized avatar

Sailesh Dhakal meSailesh

View GitHub Profile
public class Student{
public string name {get; set;}
public string standard { get; set;}
public string section {get; set;}
public int rollNumber {get; set;}
}
List<Student> sortedStudents = students.
OrderBy(x => sortedStandard.IndexOf(x.standard)).
ThenBy(x => sortedSection.IndexOf(x.section)).
ThenBy(x => x.rollNumber).ToList();
{
name : Harry
rollNumber : 1
section : B
standard : Second
},
{
name : Penny
rollNumber : 4
section : B
@meSailesh
meSailesh / sortList.cs
Last active April 24, 2022 11:24
Sort list based on other sorted list using LINQ in c sharp
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
public class SortList
{
public static void Main(string[] args)
{
List<Student> students = new List<Student>(){
List<string> sortedStandard = new List<string>() {"Second", "First", "Third"};
List<string> sortedSection = new List<string>() {"B", "A"};
List<Student> students = new List<Student>(){
new Student {name ="Bob", standard = "Third", section ="A", rollNumber=10},
new Student {name ="Smith", standard = "Second", section ="B", rollNumber=5},
new Student {name ="Tylor", standard = "first", section ="A", rollNumber=1},
new Student {name ="Jack", standard = "Third", section ="A", rollNumber=8},
new Student {name ="Penny", standard = "second", section ="B", rollNumber=4},
new Student {name ="Diana", standard = "First", section ="A", rollNumber=1},
new Student {name ="Selena", standard = "First", section ="B", rollNumber=3},
new Student {name ="Elon", standard = "Second", section ="A", rollNumber=1},
new Student {name ="Harry", standard = "Second", section ="B", rollNumber=1},
@meSailesh
meSailesh / denseRank.sql
Last active April 24, 2022 11:48
Apply distinct and dense rank in sql
CREATE TABLE TrackingData
(TrackingNumber int, City varcha, DeliveryStatus varchar);
INSERT INTO TrackingData VALUES
(1,'NewYork','Delivered'),
(1,'NewYork','Delivered'),
(2,'NewYork','Delivered'),
(3,'Seattle','Delivered'),
(3,'Seattle','Delivered'),
(3,'Seattle','NotDelivered'),