C# advanced permutation scenario

后端 未结 4 975
北恋
北恋 2021-01-20 20:55

I am trying to figure how how to find all the combinations given the following information:

I start with a JSON dataset:

var choices = { 1: {\'Q\': 1         


        
4条回答
  •  长发绾君心
    2021-01-20 22:01

    check this out: Combination Generator in Linq

    Another solution without LINQ, assuming you will be doing this on only 4 things per row, the easiest thing is to just brute force it and do nested foreach loops.

    foreach ( choice in allChoices )
    {
        foreach ( choice in allChoices )
        {
            foreach ( choice in allChoices )
            {
                foreach ( choice in allChoices )
                {
                    // combine and add to a collection
                }
            }
        }
    }
    

    edit: added objects to loop over in foreach loops

提交回复
热议问题