Click here to Skip to main content
15,888,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to pass the list to below function.

C#
public static List<List<T>> AllCombinationsOf<T>(params List<T>[] sets)
{ 
      //some set of code here
}

Now I call the function by using:
C#
var x = AllCombinationsOf(A,B,C);


I don't know the number of list that I need to pass before runtime. It will be change dynamically. How to I create the list dynamically and pass this function.

If I want to pass parameter to "AllCombinationsOf" as
C#
AllCombinationsOf(A,B,C,D); 
AllCombinationsOf(A,B);
AllCombinationsOf(A,B,C,D,E);
means what I have to do?

I have to pass parameter as dynamically( parameter that will be change)

I tried to add list into this
C#
List<List<string>> lst = new List<List<string>>();

but it not working
Posted
Updated 6-Mar-14 8:59am
v3
Comments
BillWoodruff 6-Mar-14 9:31am    
You need to clarify what you mean by "dynamically." Is the purpose of your method to transform the values passed it into it as a parameter ?

1 solution

You just list the values:
C#
    List<string> l1 = new List<string> { "heelo", "goodbye" };
    List<string> l2 = new List<string> { "heelo", "goodbye" };
    List<int> l3 = new List<int> { 1, 2, 3, 4 };
    var x = AllCombinationsOf(l1, l2);
    ...

public static List<List<T>> AllCombinationsOf<T>(params List<T>[] sets)
    {
    Console.WriteLine(sets.Length);
    return sets.ToList();
    }
Obviously, you can't add the third list into the parameters, but if you just list your params, they will be passed as an array of List-of-strings
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900