Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 乐透游戏Visual Studio_C#_Visual Studio - Fatal编程技术网

C# 乐透游戏Visual Studio

C# 乐透游戏Visual Studio,c#,visual-studio,C#,Visual Studio,我创建了一个包含6个数字的数组。我已经生成了一个介于1到40之间的随机数,但每个数都是按顺序显示的。我只需要读6 static void Main() { int temp; int number = 0; int[] lotto = new int[6]; Random rand = new Random(); for (int i = 0; i <= 40; i++)

我创建了一个包含6个数字的数组。我已经生成了一个介于1到40之间的随机数,但每个数都是按顺序显示的。我只需要读6

        static void Main()
    {
        int temp;
        int number = 0;
        int[] lotto = new int[6];

        Random rand = new Random();

        for (int i = 0; i <= 40; i++)
        {
            number = 0;
            temp = rand.Next(1, 40);

            while (number <= i)
            {
                if (temp == number)
                {
                    number = 0;
                    temp = rand.Next(1, 40);
                }
                else
                {
                    number++;
                }                    
            }
            temp = number;
            Console.WriteLine("your lotto number is " + number);
        }
            Console.ReadLine(); 
    }
}
static void Main()
{
内部温度;
整数=0;
整数[]乐透=新整数[6];
Random rand=新的Random();
对于(inti=0;i试试这个

        int number = 0;
        int[] lotto = new int[6];

        Random rand = new Random();

        for (int ctr = 1; ctr <= 6; ctr++)
        {
            number = rand.Next(1, 41);

            while (lotto.Contains<int>(number))
            {
                number = rand.Next(1, 41);
            }
            lotto[ctr-1] = number;
            Console.WriteLine("Your lotto number is: " + number);
        }

        Console.ReadLine();
int number=0;
整数[]乐透=新整数[6];
Random rand=新的Random();
对于(int-ctr=1;ctr-i).ToArray();

但您需要

使用System.Linq;

一个简单的Linq,带有orderby
Guid.NewGuid()


您从未向
乐透
数组添加任何内容。我也不确定您为什么调用random两次,但从未对值进行任何操作。is
temp=rand.Next(1,40);
应该是
number=rand.Next(1,40);
var lotto = Enumerable.Range(1, 40)
                      .OrderBy(i => Guid.NewGuid())
                      .Take(6)
                      .ToArray();