开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜