I have a List<User> collection, and I want to create a comma seperated string using the User.Id property, so:
"12321,432434,123432452,1324234"
I have done it using a loop, but was hoping someone could show me the linq way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In .NET 4:
In .NET 3.5:
The difference is that .NET 4’s overload list for
string.Joinis wider than the one in .NET 3.5, and the overload you really want is one of the “new” ones:You can still do it in .NET 2.0, just using a
List<T>-specific method instead of LINQ (I’m assuming you can still use C# 3):