如何使用c#拆分字符串通用列表 [英] how to split a string generic list using c#

查看:83
本文介绍了如何使用c#拆分字符串通用列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是:如何拆分List< string> ?有没有像拆分这样的方法。斯普利特在这里不起作用。我输出

Quote:

{Name = a,Age = 22,Salary = 10000,City = baa}

但是想要它是列式的,所以我可以将它绑定到gridview。我有数据集中的表,但我想将所有表内容复制到列表< string>?为此,我写了

  var  NameList =( from  r  dataset.Tables [<跨度类= 代码位> 0 ]。AsEnumerable()
<跨度类= 代码sdkkeyword>选择
new {Name = r.Field< string>( name),Age = r.Field< string>( age),Salary = r.Field< string>( salary),City = r .Field< string>( city)} .ToString())。ToList();







但它返回'count',即在我的情况下count = 9行数。它在索引说[0]处连接整行并给出计数(在我的情况下,计数= 10已经在上面提到过)。我没有以表格的形式输出,那么我将如何将其绑定到gridview。 thanx提前

解决方案
请看看这里:的 http://stackoverflow.com/questions/438188/split-a-collection-into-n-parts-with-linq [ ^ ]。我希望它会有所帮助。


my question is : How can i split a List<string> ? Is there any method like split. Split is not working here. I am getting output as

Quote:

{ Name = a, Age = 22, Salary = 10000, City = baa }

but want it column wise so that i can bind it to gridview. I have my table in dataset but i want to copy all the table contents to list<string>? For that i have written

var NameList = (from r in dataset.Tables[0].AsEnumerable()
                            select new { Name = r.Field<string>("name"), Age = r.Field<string>("age"), Salary = r.Field<string>("salary"), City = r.Field<string>("city") }.ToString()).ToList();




but it is returning 'count' i.e in my case count=9 the numbers of the rows. it is concatenating whole row at index say [0] and gives count (in my case count= 10 already mentioned above). i i dont get output in form of table then how will i bind it to gridview . thanx in advance.

解决方案

Please, have a look here: http://stackoverflow.com/questions/438188/split-a-collection-into-n-parts-with-linq[^]. I hope it will be helpful.


这篇关于如何使用c#拆分字符串通用列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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