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

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
Bill Software Engineer
  • 7,362
  • 23
  • 91
  • 174

2 Answers2

6

Using String.Join:

@(string.Join(company.Users.Select(u => u.UserName), ", "))
Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
5

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

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