[英]C# dynamically access variables based on user input
I am new to C# but have school project that i am working on and need some guidance. 我是C#的新手,但是我正在从事学校项目,需要一些指导。 I have multiple arrays which i termed array1, array2, array3 , array4 and so on till array9. 我有多个数组,分别称为array1,array2,array3,array4,依此类推,直到array9。 Now the user is entering digits into input box and i am splitting the input like 543 into 5 4 3 and i want to dynamically call 现在用户在输入框中输入数字,我将543之类的输入分为5 4 3,我想动态调用
array5 array4 array3. array5 array4 array3。 So basically show contents of these arrays in console. 因此,基本上在控制台中显示这些数组的内容。
string value = input.Text.ToString(); 字符串值= input.Text.ToString();
foreach (string s in Array[value[0]])
{
-- will loop through all values of array and out put
foreach (string s in Array[value[1]])
{
-- will loop through all values of array and out put
foreach (string s in Array[value[2]])
{
-- will loop through all values of array and out put
}
}
}
How do i accomplish this ? 我该如何完成? Please help 请帮忙
Try 尝试
var arrays = new List<int[]>(){array1,....,array9};
and then if you have 5, 4, 3 you can call arrays like 然后如果你有5、4、3你可以调用数组
arrays[4], arrays[3], arrays[2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.