开发者

Can we add any type of value in the list object?

开发者 https://www.devze.com 2022-12-30 22:51 出处:网络
Can we add in the list object any type of value ? Like if we List<string> str=new List<string>();

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>.

0

精彩评论

暂无评论...
验证码 换一张
取 消