Reputation: 7782
I have the following code:
@foreach (UserAccount ua in company.Users) {
@ua.userName,
}
Which would print:
user1, user2, user3,
How do I get rid of the last ","?
Upvotes: 4
Views: 489
Reputation: 56429
Using String.Join
:
@(string.Join(company.Users.Select(u => u.UserName), ", "))
Upvotes: 6
Reputation: 15217
use String.Join method. it will handle the last comma for you.
@(string.Join(company.Users.Select(x => x.userName), ", "))
Upvotes: 5