Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////////////////////////////////
- // Possible sort algorithm of Telerik's letter-based "Less Than" grid filter.
- //
- // Note: to run this example use a C# Console app or download LINQPad
- // from http://www.linqpad.net/
- //////////////////////////////////////////////////////////////////////////////
- // List<string> input = new List<string> { "someprovider01", "someprovider02", "someprovider00", "404", "1000" };
- List<string> input = new List<string> { "100", "200", "300", "400", "500", "600", "1000" };
- // Letter based sort first.
- var sortedList = from i in input
- orderby i ascending
- select i;
- sortedList.Dump(); // OUTPUT "100", "1000", "200", "300", "400", "500", "1000"
- // Create an index on the sorted list.
- var indexedList = (from i in sortedList.Select((number, index) => new { index, number })
- select i).ToDictionary(item => item.index, item => item.number);
- indexedList.Dump(); // OUTPUT 0 : "100", 1 : "1000", 2 : "200", 3 : "300", 4 : "400", 5 : "500", 6 : "1000
- // Get last postion in regards to "less than" 500
- int lastOrdinal = (from i in indexedList
- where Convert.ToInt32(i.Value) == 500
- select i.Key).Single();
- lastOrdinal.Dump(); // OUTPUT 5
- var lessThan500 = from i in indexedList
- where i.Key < lastOrdinal
- select i.Value;
- lessThan500.Dump(); // OUTPUT: 100, 1000, 200, 300, 400
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement