SoFunction
Updated on 2025-03-07

Detailed explanation of the use of C# combination functions


using System;
using ;
using ;
namespace ConsoleApplication1
{

    class Class1
    {
        static string[] str = { "A", "B", "C", "D", "E" };
        static void Main()
        {
            Dictionary<string, int> dic = new Dictionary<string, int>();
//Add array elements to dic
            for (int i = 0; i < ; i++)
            {
                (str[i], i);
            }
            GetDic(dic);
            ();
        }
        static void GetDic(Dictionary<string, int> dd)
        {
            Dictionary<string, int> dic = new Dictionary<string, int>();
//The main thing is to grasp AB, AC, AD, AE, and then start combining the principle of BC and BD using the keys in dd and the corresponding index in the array larger than the value in dd
            foreach (KeyValuePair<string, int> kk in dd)
            {
                for (int i = + 1; i < ; i++)
                {
                    ( + str[i]);
                    ( + str[i], i);
                }
            }
//recursion
            if ( > 0) GetDic(dic);
        }
    }

}
result
AB
AC
AD
AE
BC
BD
BE
CD
CE
DE
ABC
ABD
ABE
ACD
ACE
ADE
BCD
BCE
BDE
CDE
ABCD
ABCE
ABDE
ACDE
BCDE
ABCDE