简体   繁体   English

C# - 在循环内连接

[英]C# - Concatenate inside a loop

Is it possible to concatenate inside a C# loop?是否可以在 C# 循环内连接? 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 .我想要的是连接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 .数组或列表或任何其他支持使用循环索引或foreach它的东西。

So the answer is no.所以答案是否定的。 No, you cannot.你不能。 You should change the types holding your data.您应该更改保存数据的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM