How do i chop up an array with a comma between every string?

时间:2018-09-19 08:26:35

标签: javascript c# arrays entity-framework charts

I have an array that i create with this query:

public string[] Scores { get; set; } 
var scoresBetted = _context.Bet.Where(i => i.MatchId == id)
.Select(a => a.ScoreBetted).ToArray(); //ScoreBetted type string
Scores = scoresBetted;

I now want to chop up the array so that it comes out like this for example: "1-1","4-2","2-1" etc. I'm thinking that need to do with with a foreach loop but i can't find how i do it.

Why i wanna do this is because i want to dynamically create c3 categories in a chart, and those categories is an array, example here

1 个答案:

答案 0 :(得分:1)

尝试使用

var test = string.Join(@",", Model.ListOfScores.Select(x => $"'{x}'"));

这意味着它首先将每个项目放在' '中,然后以分隔,的形式加入数组

版本Fiddle