Determine if two strings with no repeating characters are permutations of each other I've made a short program to determine if a string is permutation of another string.
Example input/output :

a) 123, 112 &lt;- False
b) 123, 321 &lt;- True
c) 112, 121 &lt;- these don't count as permutations since they have duplicate characters

    private static void Main()
    {
        string a = Console.ReadLine();
        string b = Console.ReadLine();                    
        Console.WriteLine(IsPermutation(a, b));
        Console.ReadKey();
    }

    private static bool IsPermutation(string first, string second)
    {
        if (first.Length != second.Length)
        {
            return false;
        }
        for (int i = 0; i &lt; first.Length; i++)
        {
            if (first.Count(t =&gt; t == second[i]) != second.Count(t =&gt; t == first[i]))
            {
                return false;
            }
        }
        return true;
    }

I wonder if it can be optimized.
You could use the SetEqual&lt;T&gt; helper method from this answer.
It uses a dictionary as follows:


The dictionary is filled with the items of the first collection and with their number of occurences.
Number of occurences is decreased for each item in the second collection.


Thus your method can be rewritten as:

private static bool IsPermutation(string first, string second)
{
    if (first.Length != second.Length)
    {
        return false;
    }
    return SetEqual(first, second);
}




If you are sure that strings contain only unique chars, there is a more efficient approach using the HashSet&lt;T&gt;:

private static bool IsPermutation(string first, string second)
{
    if (first.Length != second.Length)
    {
        return false;
    }
    HashSet&lt;char&gt; chars = new HashSet&lt;char&gt;(first);
    return second.All(chars.Contains);
}