gpt4 book ai didi

c# - 使用多变量选择一个变量

转载 作者:太空宇宙 更新时间:2023-11-03 19:17:09 25 4
gpt4 key购买 nike

我有很多 Int32 变量,我想选择要检查的 int 。是否可以制作这条线并使用多变量选择一个变量?

Int32 redleft0 = 0; 
Int32 redleft1 = 0;
Int32 redleft2 = 0;
Int32 redleft3 = 0;
Int32 redleft4 = 0;
Int32 redleft5 = 0;
Int32 blueleft0 = 0;
Int32 blueleft1 = 0;
Int32 blueleft2 = 0;
Int32 blueleft3 = 0;
Int32 blueleft4 = 0;
Int32 blueleft5 = 0;

redorblue = "red";
for (int i = 0; i < count; i++)
{
String checkleftint = (redorblue + "left" + i);
if (checkleftint < 0)
{
}
}

最佳答案

你应该在这里使用一个数组——或者更确切地说是两个数组:

var red = new int[]{0,0,0,0,0,0};
var blue = new int[]{0,0,0,0,0,0};

var arrayToUse = redorblue == "red" ? red : blue;
for (int i = 0; i < count; i++)
{
var value = arrayToUse[i];
// ....
}

关于c# - 使用多变量选择一个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15500508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com