Is there a more efficient way to do this using LINQ or String.Join?
var sb = new StringBuilder();
foreach (var s in cls.Students)
sb.Append("<div id=\"s" + s.Id + "\">" + s.FirstName +
" " + s.LastName + "</div>");
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.
You can use
string.Concat:It’s a little more concise, but it probably won’t give you more performance. Using a
StringBuilderis already very efficient.Notes
.ToArray()just before the last parenthesis.s.FirstNameands.LastName. I’m assumings.IDis an integer and therefore is safe.