Can we add any type of value in the list object?
Can we add in the list object any type of value ?
Like if we
List<string> str=new List<string>();
then only st开发者_高级运维ring value can be added to list.But I want to add any type of value in the list like string,decimal.
Then you can use none generic type of List.
Use ArrayList
or even you can use List<object>
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>
.
精彩评论