List<T> add method in C#
- by Nano HE
Hello.
As I know. List Add method works as below.
List<string> cities = new List<string>();
cities.Add("New York");
cities.Add("Mumbai");
cities.Add("Berlin");
cities.Add("Istanbul");
If I designed the data structure as this
List<object> lstObj = new List<object>();
if (true) // string members
{
cities.Add("New York");
cities.Add("Istanbul");
}
else // List obj members here
{
List<object> AListObject= new List<object>();
cities.Add(AListObject); // how to handle this?
}
Does the List Add method works or not if I add different types members in the same function.