简体   繁体   中英

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 ?

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()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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