Mehrdad_gh
Mehrdad_gh

Reputation: 29

How to use items of an array as names for other variables c#

I have a list of names in an array and i would like to use these names to assign them to new lists like bellow:

    var list = new string[]{"bot1","bot2","bot3"};  
    List<string> list[0] = new List<string>();  

but i am getting the error: a local variable or function named 'list' is already defined in this scope.

is there a work around !!? your input will be greatly appreciated.

Upvotes: 1

Views: 279

Answers (2)

Wolfram Wisser
Wolfram Wisser

Reputation: 39

If you only need a integer as key than you can also use this solution.

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

list.Add(new List<string>{ {"A"} });

list[0][0] = "..";

Upvotes: 0

gabba
gabba

Reputation: 2880

I think you can store your bots in dictionary:

var bots = new Dictionary<string,List<string>>();
bots[name] = new List<string>();
bots[name].Add("some str");

Upvotes: 3

Related Questions