這個代碼是越野車,但無法弄清楚爲什麼...想用7個獨特的隨機整數填充數組而不使用數組列表或linq!我知道這個邏輯是不行的......C#使用唯一整數填充數組無Linq或ArrayLists;
class Program
{
static void Main(string[] args)
{ int current;
int[] numbers = new int[7]; // size of that array
Random rNumber = new Random();
current = rNumber.Next(1, 50);
numbers[0] = current;
Console.WriteLine("current number is {0}", current);
for (int i=1;i<7;i++)
{
current = rNumber.Next(1, 50);
for (int j = 0; j < numbers.Length; j++)
{
do
{
if (current == numbers[j])
{
Console.WriteLine("Duplicate Found");
current = rNumber.Next(1, 50);
}
else
{
numbers[j++] = current;
break;
}
}while (current == numbers[j]);
}//inner for
}//outer for
for (int l = 0; l < 7; l++) // DISPLAY NUMBERS
{
Console.WriteLine(numbers[l]);
}
}// main
}//class
這是我承擔的功課嗎? – BrokenGlass
您是否嘗試過使用調試器? –
它是brokenglass – Marin