1
static IEnumerable<string> GetCombinations(string s, int length) 
{
    if (length > s.Length || length == 0)
    {
        return new[] { String.Empty };
        if (length == 1)
        {
            return s.Select(c => new string(new[] { c }));
        }
    }
    return from c in s
    from combination in GetCombinations(
      s.Remove(s.IndexOf(c), 1),
      length - 1
    )
    select c + combination;
}

This code work in strings.But I want ArrayList Combinations..For Example,

Arraylist.add('a,b');
Arraylist.add('a,c');
Arraylist.add('f,g');
Arraylist.add('h,l');

for length=3

'a,b,c','a,b,f','a,b,g'........

I'm sorry I'm new to C #.. Very even though I tried I could not.. Do you have an idea for this?

4

0 回答 0