zoukankan      html  css  js  c++  java
  • 无解的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看了下不是这样的。

  • 相关阅读:
    lighting
    移动端
    SVN常见问题
    前四章知识点小结
    如何不运用第三方变量实现两个数的交换
    awk
    sort
    cut
    sed
    30道Linux面试题
  • 原文地址:https://www.cnblogs.com/glorysword/p/2293485.html
Copyright © 2011-2022 走看看