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 ","?
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 ","?
Using String.Join
:
@(string.Join(company.Users.Select(u => u.UserName), ", "))
use String.Join method. it will handle the last comma for you.
@(string.Join(company.Users.Select(x => x.userName), ", "))