Pawan
Pawan

Reputation: 167

List Name as string in c#

I want to create a list of strings whose name should be the value of string variable.

Overall I want to assign a variable value to a (object) listname.

(Pseudo Code):

string s = "listname";
list<String>.Name = s;

Upvotes: 0

Views: 1127

Answers (1)

RagtimeWilly
RagtimeWilly

Reputation: 5445

Closest thing you can do is use a Dictionary to reference the variables.

Dictionary<string, List<string>> myLists = new Dictionary<string, List<string>>();

var s = "listname";
myLists.Add(s, new List<string>());

// To access
var list = myLists[s];

Upvotes: 2

Related Questions