Created
February 14, 2020 12:09
-
-
Save ProductiveRage/2087aca15f790fc90ef68c3876d90ad5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace Tester | |
{ | |
static void Main() | |
{ | |
var nameOccurrences = | |
new[] | |
{ | |
new MyNamedItem { Name = "Dan" }, | |
new MyNamedItem { Name = "Dan" }, | |
new MyNamedItem { Name = "Ted" }, | |
new MyNamedItem { Name = "Dan" }, | |
new MyNamedItem { Name = "Dan" } | |
} | |
.MyGroupBy(value => value.Name, null) | |
.Select(group => new { Name = group.Key, Count = group.Count() }); | |
Console.WriteLine(string.Join(", ", nameOccurrences.Select(name => name.Name + ": " + name.Count))); | |
Console.ReadLine(); | |
} | |
public static class MyEnumerableExtensions | |
{ | |
public static IEnumerable<IGrouping<TKey, TSource>> MyGroupBy<TSource, TKey>( | |
this IEnumerable<TSource> source, | |
Func<TSource, TKey> keySelector, | |
IEqualityComparer<TKey> comparer) | |
{ | |
throw new NotImplementedException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment