逗号分隔字符串内置 .NET
我使用内置函数轻松使用 List 创建逗号分隔的字符串。 (它不是拆分和连接,而是新功能)我无法回忆或找到它。如果有人知道并使用它,请发布一个链接。框架 - .net 2.0
(它不是连接或拆分 - 我知道这一点,.net 有新的内置函数来创建 CSV 格式)
检查下面的 Jacob G 答案以了解我正在寻找的内容,让我知道您的想法与加入相比;)
无论是谁给了我 -ve 代表都需要保持耐心,不要着急
I used a built in function to create comma separated string using List easily.
(It is not split and join but new function) I'm not able to recollect or find it. If some one knows about it and uses it please post a link to that. Framework - .net 2.0
(It is not Join or split - I know about this, .net has new built in function to create CSV format)
Check Jacob G Answer below for what I was looking for let me know your thoughts on it compared to join ;)
And whoever gave me -ve rep need to keep some patience and not hurry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
附:不要投票,只是玩得开心。
ps. don't downvote, just having fun.
这可能就是您正在考虑的...您需要引用 System.Configuration dll 并导入适当的命名空间。
顺便说一句,我通过打开文档并在索引中键入单词“逗号”找到了这个类。
编辑
回答您的新问题 - 假设您的列表已经构建, String.Join 的性能将会更高。该集合仅使用 StringBuilder。 String.Join 有许多低级优化,可以使其速度更快。
(另外,在换成新问题后拿走“正确答案”也不是很酷)
This might be what you're thinking of... You need to reference the System.Configuration dll and import the appropriate namespace.
By the way, I found this class by opening up the documentation and typing the word "comma" in the index.
EDIT
In response to your new question - Assuming that your List is already constructed, String.Join is going to be more performant. This collection just uses a StringBuilder. String.Join has a number of low-level optimization that will make it faster.
(also, not terribly cool to take away the "correct answer" after you change to a new question)
开箱即用,我认为
List
没有任何方法或属性可以执行此操作。我同意 jsmith 的观点,它一定是一种扩展方法,等等。Out of the box, I don't think
List<T>
has any methods or properties which do this. I agree with jsmith it must have been an extension method, etc.我相信您正在寻找 String.Join 方法?
I believe you are looking for the String.Join method?