String - IsAnagram

A string extension method that query if the string object is anagram of other String.

Try it

public static void Main()
{
	string [] values = {"EntityFramework", "restful"};

	foreach(var str in values)
	{
		// C# Extension Method: String - IsAnagram
    	if(str.IsAnagram("fluster"))
		{
			Console.WriteLine("{0} and {1} are anagrams", str, "fluster");
		}
		else
		{
			Console.WriteLine("{0} and {1} are not anagrams", str, "fluster");
		}
	}
}

View Source
using System.Linq;

public static partial class Extensions
{
    /// <summary>
    ///     A string extension method that query if '@this' is anagram of other String.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="otherString">The other string</param>
    /// <returns>true if the @this is anagram of the otherString, false if not.</returns>
    public static bool IsAnagram(this string @this, string otherString)
    {
        return @this
            .OrderBy(c => c)
            .SequenceEqual(otherString.OrderBy(c => c));
    }
}