如何将列表字符串添加到列表中 [英] How to add list strings to a list

查看:203
本文介绍了如何将列表字符串添加到列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有4个列表字符串。

如何将所有这些字符串添加到列表中?



谢谢

John

Hi,

I have 4 list strings.
How can I add all of them to a list??

Thanks
John

推荐答案

List<string> lst1 = new List<string>();        
        List<string> lst2 = new List<string>();      
        List<string> lst3 = new List<string>();
        List<string> lst4 = new List<string>();

        List<string> lstFinal  = new List<string>();
        lstFinal.AddRange(lst1);
        lstFinal.AddRange(lst2);
        lstFinal.AddRange(lst3);
        lstFinal.AddRange(lst4);





参考:将列表数据添加到另一个列表 [ ^ ]


List<string> initialList = new List<string>();
// Put whatever you want in the initial list
List<string> listToAdd = new List<string>();
// Put whatever you want in the second list
initialList.AddRange(listToAdd);





使用List.AddRange(集合为IEnumerable(Of T))方法。

It允许您在列表的末尾添加另一个集合/列表。

试试这个。



Use List.AddRange(collection As IEnumerable(Of T)) method.
It allows you to append at the end of your list another collection/list.
Try this.


这篇关于如何将列表字符串添加到列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆