Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Dynamic List Name

Tags:

c#

.net

I need to create few list in c# but want to name those list dynamically according to some condition.

For example

List<string> x1= new List<string>();
List<string> x2 = new List<string>();

The name "x1" and "x2" would come at runtime (probably from some file or something). Is there any way to achieve this ?

like image 721
knowledgeseeker Avatar asked Nov 23 '25 11:11

knowledgeseeker


1 Answers

Create Dictionary<string, List<string>>:

var dict = new Dictionary<string, List<string>>();

dict["x1"] = new List<string>();

You can replace "x1" with variable.

like image 73
MarcinJuraszek Avatar answered Nov 25 '25 03:11

MarcinJuraszek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!