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 ?
Create Dictionary<string, List<string>>:
var dict = new Dictionary<string, List<string>>();
dict["x1"] = new List<string>();
You can replace "x1" with variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With