How to create dynamic incrementing variable using “for” loop in C#

后端 未结 6 608
南方客
南方客 2021-01-07 03:42

How to create dynamic incrementing variable using \"for\" loop in C#? like this: track_1, track_2, track_3, track_4. so on.

6条回答
  •  孤街浪徒
    2021-01-07 04:13

    You can't create dynamically-named variables. All you can do - it to create some collection or array, and operate with it. I think the best class for you is generic List<>:

    List listWithDynamic = new List();
    for (int i = 1; i < limit; i +=1)
    {
        listWithDynamic.Add(string.Format("track_{0}", i));
        ...
    }
    

提交回复
热议问题