Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Rank
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public static class Program { public static void Main(string[] args) { string[] myNames = new string[] { "Bob", "Mark", "John", "Jim", "Lisa", "Dave" }; var query = myNames.Rank(s => s.Length, (s, r) => new { s, r }); foreach (var x in query) { Console.WriteLine("{0} {1}", x.r, x.s); } } public static IEnumerable<U> Rank<T, TKey, U> ( this IEnumerable<T> source, Func<T, TKey> keySelector, Func<T, int, U> selector ) { if (!source.Any()) { yield break; } int itemCount = 0; T[] ordered = source.OrderBy(keySelector).ToArray(); TKey previous = keySelector(ordered[0]); int rank = 1; foreach (T t in ordered) { itemCount += 1; TKey current = keySelector(t); if (!current.Equals(previous)) { rank = itemCount; } yield return selector(t, rank); previous = current; } } } }
run
|
edit
|
history
|
help
0
1
decimal to binary
Task 1_3
Fibonacci recursion
Range List for C#
database interior 0.2
RGEFCSZX
Check if string is palindrome
Generics
Array Comparison