Can we add in the list object any type of value ?
Like if we
List<string> str=new List<string>();
then only string value can be added to list.But I want to add any type of value in the list like string,decimal.
Can we add in the list object any type of value ?
Like if we
List<string> str=new List<string>();
then only string value can be added to list.But I want to add any type of value in the list like string,decimal.
You can use the non generic equivalent of List<T> which is System.Collections.ArrayList.
var list = new System.Collections.ArrayList();
list.Add("test");
list.Add(1);
Or you could use List<object>.
Then you can use none generic type of List.
Use ArrayList or even you can use List<object>