简体   繁体   English

使用Linq返回逗号分隔的字符串

[英]Using Linq to return a Comma separated string

I have a class in my application 我的申请中有课程

public class ProductInfo
{
  public int ProductId {get;set;}
  public int ProductType{get;set;}
}

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查询,该查询可以用逗号分隔的格式返回ProductId的列表,其中ProductType等于某个数字?

I tried using string.join with my Linq statement but it didn't seem to work. 我在Linq语句中尝试使用string.join,但似乎没有用。

var s = string.Join(",", products.Where(p => p.ProductType == someType)
                                 .Select(p => p.ProductId.ToString()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM