使用Linq返回逗号分隔的字符串 [英] Using Linq to return a Comma separated string
本文介绍了使用Linq返回逗号分隔的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序中有一个课程
I have a class in my application
public class ProductInfo
{
public int ProductId {get;set;}
public int ProductType{get;set;}
}
我想编写一个linq查询,该查询可以用逗号分隔的格式返回ProductId的列表,其中ProductType等于某个数字?
I want to write a linq query which can return me a list of ProductIds in a comma separated format where ProductType is equal to certain number ?
我尝试在我的Linq语句中使用string.join,但似乎没有用.
I tried using string.join with my Linq statement but it didn't seem to work.
推荐答案
var s = string.Join(",", products.Where(p => p.ProductType == someType)
.Select(p => p.ProductId.ToString()));
这篇关于使用Linq返回逗号分隔的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文