Click here to Skip to main content
15,922,419 members
Home / Discussions / C#
   

C#

 
AnswerRe: Combinations Pin
Luc Pattyn28-Apr-10 11:54
sitebuilderLuc Pattyn28-Apr-10 11:54 
AnswerRe: Combinations Pin
PIEBALDconsult28-Apr-10 14:07
mvePIEBALDconsult28-Apr-10 14:07 
GeneralRe: Combinations Pin
James Towers28-Apr-10 14:29
James Towers28-Apr-10 14:29 
GeneralRe: Combinations Pin
PIEBALDconsult28-Apr-10 16:25
mvePIEBALDconsult28-Apr-10 16:25 
AnswerRe: Combinations Pin
Luc Pattyn28-Apr-10 14:45
sitebuilderLuc Pattyn28-Apr-10 14:45 
GeneralRe: Combinations Pin
James Towers28-Apr-10 15:20
James Towers28-Apr-10 15:20 
GeneralRe: Combinations Pin
Luc Pattyn28-Apr-10 15:28
sitebuilderLuc Pattyn28-Apr-10 15:28 
AnswerRe: Combinations Pin
PIEBALDconsult28-Apr-10 19:20
mvePIEBALDconsult28-Apr-10 19:20 
Here's a generic version of a "one from column A, one from column B" algorithm.
Any number of columns should work and they don't need to all have the same number of items.
Empty columns are ignored (not tested).

public static System.Collections.Generic.IList<System.Collections.Generic.IList<T>>
MakeCombinations<T>
(
    params System.Collections.Generic.IEnumerable<T>[] Values
)
{
    System.Collections.Generic.List<System.Collections.Generic.IList<T>> result =
        new System.Collections.Generic.List<System.Collections.Generic.IList<T>>() ;

    if ( Values != null )
    {
        result.Add ( new System.Collections.Generic.List<T>().AsReadOnly() ) ;

        for ( int i = Values.Length - 1 ; i >= 0 ; i-- )
        {
            if ( Values [ i ] != null )
            {
                System.Collections.Generic.List<System.Collections.Generic.IList<T>> temp =
                    new System.Collections.Generic.List<System.Collections.Generic.IList<T>>() ;

                foreach ( T t in Values [ i ] )
                {
                    foreach ( System.Collections.Generic.IList<T> many in result )
                    {
                        System.Collections.Generic.List<T> one =
                            new System.Collections.Generic.List<T>() ;

                        one.Add ( t ) ;

                        one.AddRange ( many ) ;

                        temp.Add ( one.AsReadOnly() ) ;
                    }
                }

                if ( temp.Count > 0 )
                {
                    result = temp ;
                }
            }
        }
    }

    return ( result.AsReadOnly() ) ;
}

System.Collections.Generic.IList<System.Collections.Generic.IList<string>> c =
MakeCombinations
(
    new string[] { "Blonde" , "Brunette" , "Redhead" , "Black" }
,
    new string[] { "Blue" , "Brown" , "Green" }
,
    new string[] { "A" , "B" , "C" , "D" , "DD" , "DDD" }
) ;


Now I need to get to bed...
QuestionDisplay a PDF in a Windows C# program. Pin
jbradshaw28-Apr-10 10:57
jbradshaw28-Apr-10 10:57 
QuestionRe: Display a PDF in a Windows C# program. Pin
AspDotNetDev28-Apr-10 21:02
protectorAspDotNetDev28-Apr-10 21:02 
AnswerRe: Display a PDF in a Windows C# program. Pin
Kythen29-Apr-10 7:26
Kythen29-Apr-10 7:26 
GeneralRe: Display a PDF in a Windows C# program. Pin
jbradshaw30-Apr-10 7:45
jbradshaw30-Apr-10 7:45 
QuestionCross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
igalep13228-Apr-10 9:04
igalep13228-Apr-10 9:04 
AnswerRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
Not Active28-Apr-10 9:12
mentorNot Active28-Apr-10 9:12 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
igalep13228-Apr-10 9:25
igalep13228-Apr-10 9:25 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
Not Active28-Apr-10 9:40
mentorNot Active28-Apr-10 9:40 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
igalep13228-Apr-10 9:48
igalep13228-Apr-10 9:48 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
Not Active28-Apr-10 10:21
mentorNot Active28-Apr-10 10:21 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
igalep13228-Apr-10 10:26
igalep13228-Apr-10 10:26 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
Not Active28-Apr-10 11:21
mentorNot Active28-Apr-10 11:21 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
igalep13228-Apr-10 11:46
igalep13228-Apr-10 11:46 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
igalep13230-Apr-10 22:47
igalep13230-Apr-10 22:47 
AnswerRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
AspDotNetDev28-Apr-10 13:51
protectorAspDotNetDev28-Apr-10 13:51 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
igalep13230-Apr-10 21:24
igalep13230-Apr-10 21:24 
GeneralRe: Cross-thread operation not valid: Control '' accessed from a thread other than the thread it was created on repair doesnt work Pin
AspDotNetDev1-May-10 8:51
protectorAspDotNetDev1-May-10 8:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.