高手请进来 一般人解决不了
很奇怪的问题?
下面的代码用调试单步能生成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();
computer[1].Price = 5000;
computer[1].Date = "2010-12-09";
computer[1].Type = "IBM001";
computer[1].ShowID();
computer[2].Price = 8000;
computer[2].Date = "2012-12-09";
computer[2].Type = "IBM002";
computer[2].ShowID();
// computer[0].ShowType(computer);
Console.WriteLine("电脑型号\t价格为\t\t购买日期为\t\t电脑编号");
foreach (Computer item in computer)
{
Console.WriteLine("{0}\t\t{1}\t\t{2}\t\t{3}",item.Type,item.Price,item.Date,item.ID);
}
Console.ReadLine();
}
}
下面的代码用调试单步能生成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();
computer[1].Price = 5000;
computer[1].Date = "2010-12-09";
computer[1].Type = "IBM001";
computer[1].ShowID();
computer[2].Price = 8000;
computer[2].Date = "2012-12-09";
computer[2].Type = "IBM002";
computer[2].ShowID();
// computer[0].ShowType(computer);
Console.WriteLine("电脑型号\t价格为\t\t购买日期为\t\t电脑编号");
foreach (Computer item in computer)
{
Console.WriteLine("{0}\t\t{1}\t\t{2}\t\t{3}",item.Type,item.Price,item.Date,item.ID);
}
Console.ReadLine();
}
}
...全文
相关推荐
jm86编码流程图(一般人我是不给的啊)
jm86编码流程图(一般人我是不给的啊)jm86编码流程图(一般人我是不给的啊)
seo绝密教程,一般人我不告诉他
seo绝密教程,一般人我不告诉他 经典SEO教程seo八大秘籍
一种用在手机上的听歌的软件,音质比较好,用起来比较方便,操作简易,易上手啊,界面也是比较简洁,好看的,用过就知道了,下载吧,下了就知道,一般人我不告诉他!
一种用在手机上的听歌的软件,音质比较好,用起来比较方便,操作简易,易上手啊,界面也是比较简洁,好看的,用过就知道了,下载吧,下了就知道,一般人我不告诉他!
专题讲座资料(2021-2022年)动物科学专业“走出去请进来”的校企合作人才培养模式.doc
总结来说,“走出去,请进来”的校企合作模式是一种适应畜牧业发展趋势,强化理论与实践相结合,提高学生综合素质和就业竞争力的教学改革。
解决IP很多解决不了的问题
解决IP很多解决不了的问题


