【发布时间】:2020-09-26 10:38:30
【问题描述】:
好的,所以我是编码新手,我刚刚在这里开设了一个帐户以获得一些帮助。 我的任务是编写一个应用程序,该应用程序将在控制台中打印 0-100 的数字。但不是“32、44 和 77”。 我知道我可以做很多 If 语句,但我的问题是我是否可以将这三个数字存储在一个数组中,然后说:
int numZero = 0;
int[] num = { 32, 44, 77 };
while (numZero <= 100)
{
Console.WriteLine(numZero);
numZero++;
// I know the num needs to have a value assigned. But can I make the "numZero" go through the three numbers in num?
if (numZero == num [])
{
numZero++;
}
感谢您的建议!
【问题讨论】:
-
除非明确指示您使用数组,否则我会使用 for 循环 并将循环变量显式与 32、44 和 47 进行比较。
-
使用 System.Linq; => num.Contains(numZero);
标签: c# arrays .net console integer