1

How can I create lists dynamically inside loops

say, I have a list of name

like this:

List<string> names = new List<string>();

name.add("name1");

name.add("name2");

name.add("name3");

I would like to have Lists from above list (names)

Like

List<string> name1 = new List<string>();

List<string> name2 = new List<string>();

List<string> name3 = new List<string>();

really appreciate it

Matt Rowland
  • 4,575
  • 4
  • 25
  • 34
rebh. a.m
  • 97
  • 1
  • 5
  • Can you share what you have tried? – Matt Rowland Jun 26 '16 at 20:27
  • 1
    Wouldn't a [**Dictionary**](https://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx) be better for this purpose? – Visual Vincent Jun 26 '16 at 20:29
  • Or maybe a nested [**Tuple**](https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx) if nesting goes even beyond (a list of lists of lists, for example) – mishamosher Jun 26 '16 at 20:34
  • of course that there is an error, `t.ToString()` is of type _string_, while the list initializator expects an `IEnumerable`, like `new[] {"a", "b", "c"}` - **Edited** There was a comment of the author of the question asking for a specific issue on a sample code – mishamosher Jun 26 '16 at 20:46
  • your not really making sense.... why cant you just create a list in the loop. you need to give more code... so we can try and work out what you are trying to achieve. – Seabizkit Jun 26 '16 at 21:38

0 Answers0