Skip to content

Commit

Permalink
Merge pull request #127 from BethMassi/master
Browse files Browse the repository at this point in the history
Add samples for LINQ GroupBy
  • Loading branch information
BethMassi committed Nov 17, 2015
2 parents c31d29e + 01aa9b9 commit ca0fdef
Show file tree
Hide file tree
Showing 13 changed files with 1,130 additions and 0 deletions.
27 changes: 27 additions & 0 deletions samples/linq/csharp/grouping/AnagramEqualityComparer.cs
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);
}
}
}

16 changes: 16 additions & 0 deletions samples/linq/csharp/grouping/Customer.cs
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>();
}
}

0 comments on commit ca0fdef

Please sign in to comment.