高手请进来 一般人解决不了
很奇怪的问题?
下面的代码用调试单步能生成3个不同的随机数,但是直接运行,3个随机数相同 ,求解释???
我使用注释的代码运行又能生成3个不同的随机数, 求解释?、、
namespace Computer
{
class Computer
{
public Computer() { }
/// <summary>
/// 价格
/// </summary>
public int Price { get; set; }
/// <summary>
/// 购买日期
/// </summary>
public string Date { get; set; }
/// <summary>
/// 电脑ID
/// </summary>
public string ID { get; set; }
/// <summary>
/// 型号
/// </summary>
public string Type { get; set; }
public void ShowID() {
Random rand = new Random();
this.ID = Type +"--"+ rand.Next(1000,9999);
}
//public void ShowType(Computer[] comp) {
// Random rand = new Random();
// foreach (Computer item in comp)
// {
// item.ID = Type + "--" + rand.Next(1000, 9999);
// }
// }
}
class Program
{
static void Main(string[] args)
{
Computer[] computer = new Computer[] { new Computer(),new Computer(),new Computer()};
computer[0].Price = 10000;
computer[0].Date = "2009-12-09";
computer[0].Type = "HP001";
computer[0].ShowID();
&nbs