How to check if strings are anagram or not

In this I will show that how can we check if two strings are anagram or not.

Lets take example :

string myString1 = "vaibhav";
string myString2 = "bhavvai";

I want to check if this two strings are anagram or not.
There very simple way of doing it. We will have to create one function which will sort characters of both strings & then we will compare it.
Bellow is function

private string Alpha(string myString)
{
   char[] a = myString.ToCharArray();
   Array.Sort(a);
   return new string(a);
}

This function can be used to check if both strings are anagram or not like this.

if (Alpha(myString1) == Alpha(myString2))
{
   Console.WriteLine("it is anagram");
}
else
{
   Console.WriteLine("it is not anagram");
}

Like this we can check of strings are anagram or not.

admin