Is it possible to concatenate inside a C# loop? Below is my sample code:
for (int i = 0; i <= metricCount; i++)
{
if (m.metrictNumber == i)
{
aggrgt.Add(new PlainBrgDataSummaryChartAggrgt
{
scoreWk6 = scoresPerDuration.scoresPerDuration.scoreWk6.metricScore1,
scoreWk5 = scoresPerDuration.scoresPerDuration.scoreWk5.metricScore1,
scoreWk4 = scoresPerDuration.scoresPerDuration.scoreWk4.metricScore1,
scoreWk3 = scoresPerDuration.scoresPerDuration.scoreWk3.metricScore1,
scoreWk2 = scoresPerDuration.scoresPerDuration.scoreWk2.metricScore1,
scoreWk1 = scoresPerDuration.scoresPerDuration.scoreWk1.metricScore1
});
}
}
What I want is to concatenate metricScore1
.
Here's what I tried:
scoreWk6 = scoresPerDuration.scoresPerDuration.scoreWk6.metricScore + i,
Is that possible?
You cannot. If you see numbers in variable names, it's probably wrong. Numbering your variables means you should have used a container type. Either an array or a list or anything else that supports going through it with a loop index or foreach
.
So the answer is no. No, you cannot. You should change the types holding your data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.