I have two lists.
List<string> listString;
List<int> listInt;
The input I get in is
List<object>
At runtime, is there a way to convert
List<object>
to another List?
Edit: My question is how do I it at runtime. Not compile time.
I have two lists.
List<string> listString;
List<int> listInt;
The input I get in is
List<object>
At runtime, is there a way to convert
List<object>
to another List?
Edit: My question is how do I it at runtime. Not compile time.
List<string> listString = listObject.Cast<string>().ToList();
List<int> listInt = listObject.Cast<int>().ToList();
Try using the .OfType()
filter to get the specific lists.
var all = new List<object>();
// add stuff
List<string> text = all.OfType<string>().ToList();
List<int> vals = all.OfType<int>().ToList();