4

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 ","?

mattytommo
  • 54,375
  • 15
  • 123
  • 144
Bill Software Engineer
  • 6,708
  • 20
  • 82
  • 151

2 Answers2

6

Using String.Join:

@(string.Join(company.Users.Select(u => u.UserName), ", "))
mattytommo
  • 54,375
  • 15
  • 123
  • 144
5

use String.Join method. it will handle the last comma for you.

@(string.Join(company.Users.Select(x => x.userName), ", "))
Sly
  • 14,608
  • 12
  • 60
  • 89