user662285 user662285 - 1 month ago 4x
C# Question

show only distinct String.Join

I am using below code to append diffrent Product with comma but the problem is if i get the same name again then how to show only distinct value.

Eg-> AA,BB,CC,DD - This is correct
but in some scenarios i get value as AA,AA,AA,AA then i want to show as 'AA' only.

I am currently using as :

ProductName = String.Join(",", g.Select(s => s.ProductName))



You can use the Distinct() extension method on the result of your Select method call.

String.Join(",", g.Select(s => s.ProductName).Distinct())