Skip to content

Commit ca0fdef

Browse files
committed
Merge pull request dotnet#127 from BethMassi/master
Add samples for LINQ GroupBy
2 parents c31d29e + 01aa9b9 commit ca0fdef

13 files changed

+1130
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Grouping
5+
{
6+
//Comparer that matches words that are anagrams of each other.
7+
public class AnagramEqualityComparer : IEqualityComparer<string>
8+
{
9+
public bool Equals(string x, string y)
10+
{
11+
return getCanonicalString(x) == getCanonicalString(y);
12+
}
13+
14+
public int GetHashCode(string obj)
15+
{
16+
return getCanonicalString(obj).GetHashCode();
17+
}
18+
19+
private string getCanonicalString(string word)
20+
{
21+
char[] wordChars = word.ToCharArray();
22+
Array.Sort<char>(wordChars);
23+
return new string(wordChars);
24+
}
25+
}
26+
}
27+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
3+
namespace Grouping
4+
{
5+
public class Customer
6+
{
7+
public int CustomerId { get; set; }
8+
public string CustomerName { get; set; }
9+
public string Address { get; set; }
10+
public string City { get; set; }
11+
public string PostalCode { get; set; }
12+
public string Country { get; set; }
13+
public string Phone { get; set; }
14+
public IEnumerable<Order> Orders { get; set; } = new List<Order>();
15+
}
16+
}

0 commit comments

Comments
 (0)