无解的Random

     在学习LINQ的时候想到用随机生成的数组来做实验就写了几行代码。

 int[] _array=new int[10];

for (int i = 0; i < 10;i++ )
{
Random ss = new Random();
_array[i] = ss.Next(10);

}
for (int i = 0; i < 10;i++ )
{
Console.WriteLine(_array[i]);
}
Console.ReadLine();

结果就悲剧了 !

然后我就把代码换了一下位置

 int[] _array=new int[10];
Random ss = new Random();//就是这把它换了出来
for (int i = 0; i < 10;i++ )
{

_array[i] = ss.Next(10);

}
for (int i = 0; i < 10;i++ )
{
Console.WriteLine(_array[i]);
}
Console.ReadLine();

就可以了!

不知道为什么会出现这种情况!难道说引用对象的时间比计数的时间要小的多!

结果用Stopwatch看了下不是这样的。

原文地址:https://www.cnblogs.com/glorysword/p/2293485.html