Skip to content

Instantly share code, notes, and snippets.

@ProductiveRage
Created February 14, 2020 12:09
Show Gist options
  • Save ProductiveRage/2087aca15f790fc90ef68c3876d90ad5 to your computer and use it in GitHub Desktop.
Save ProductiveRage/2087aca15f790fc90ef68c3876d90ad5 to your computer and use it in GitHub Desktop.
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