MADMAX
MADMAX

Reputation: 160

How to display list of string with double quote separated by comma in Razor page c#?

             labels: [@foreach (var item in new string[]{"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN"})
             {
                @item
             }]

With this code I am able to get result as ONETWOTHREEFOURFIVESIXSEVENEIGHTNINETEN, The expected result i want to get inside label is "ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN"

Upvotes: 0

Views: 147

Answers (1)

Guokas
Guokas

Reputation: 830

You can use the String.Format, change your code as follows:

labels: [@foreach (var item in new string[]{"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN"})
{
    @String.Format("\"{0}\"{1}", item,!item.Equals("TEN")?",":"")
}

Upvotes: 1

Related Questions