Time for action – finding anagrams the easiest way

As they say, if all you have is a hammer, every problem would seem like a nail. Finding an anagram is similar to finding whether two sorted character sets exactly match with each other or not. OrderedBag<T> collection from Power Collections is perfect for this job. I can't emphasize this more. Let's see how we can do it:

  1. Create a Console Application project and call it AnaCheck.
  2. Add PowerCollections.dll reference to the project.
  3. Now add the following lines of code in the Main() method:
    static void Main(string[] args) { OrderedBag<char> first = new OrderedBag<char>("dad"); OrderedBag<char> second = new OrderedBag<char>("add"); bool isAna = Algorithms.EqualCollections(first, second); if(isAna) Console.Write("\"dad\" ...

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.