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
答案 0 :(得分:1)
尝试使用
var test = string.Join(@",", Model.ListOfScores.Select(x => $"'{x}'"));
这意味着它首先将每个项目放在' '
中,然后以分隔,
的形式加入数组
版本Fiddle