-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from BethMassi/master
Add samples for LINQ GroupBy
- Loading branch information
Showing
13 changed files
with
1,130 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Grouping | ||
{ | ||
//Comparer that matches words that are anagrams of each other. | ||
public class AnagramEqualityComparer : IEqualityComparer<string> | ||
{ | ||
public bool Equals(string x, string y) | ||
{ | ||
return getCanonicalString(x) == getCanonicalString(y); | ||
} | ||
|
||
public int GetHashCode(string obj) | ||
{ | ||
return getCanonicalString(obj).GetHashCode(); | ||
} | ||
|
||
private string getCanonicalString(string word) | ||
{ | ||
char[] wordChars = word.ToCharArray(); | ||
Array.Sort<char>(wordChars); | ||
return new string(wordChars); | ||
} | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Grouping | ||
{ | ||
public class Customer | ||
{ | ||
public int CustomerId { get; set; } | ||
public string CustomerName { get; set; } | ||
public string Address { get; set; } | ||
public string City { get; set; } | ||
public string PostalCode { get; set; } | ||
public string Country { get; set; } | ||
public string Phone { get; set; } | ||
public IEnumerable<Order> Orders { get; set; } = new List<Order>(); | ||
} | ||
} |
Oops, something went wrong.