Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Linq to return a Comma separated string

Tags:

c#

linq

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.

like image 242
Mako Avatar asked Sep 24 '13 20:09

Mako


1 Answers

var s = string.Join(",", products.Where(p => p.ProductType == someType)                                  .Select(p => p.ProductId.ToString())); 
like image 197
King King Avatar answered Oct 10 '22 10:10

King King