using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace instance
{
class Program
{
static void Main(string[] args)
{
int[] num = new int[3];
//计算出四位的随机数
Random ran = new Random();
for (int i = 0; i < num.Length; i++)
{
num[i] = ran.Next(1000, 10000);
}
//利用数组储存数据
computer[] com = new computer[3];
computer com1 = new computer("hpCQ-217TX", "2013-10-05", "");
computer com2 = new computer("Mc240CH", "2013-10-05", "");
computer com3 = new computer("SYNW18H", "2013-10-05", "");
com[0] = com1;
com[1] = com2;
com[2] = com3;
Console.WriteLine("************************设置计算机ID前*************************" + "\n");
Console.WriteLine("计算机型号\t计算机ID\t购买时间");
foreach (computer item in com)
{
Console.WriteLine(item.Type + "\t\t" + item.ID + "\t\t" + item.Time);
}
//拼接 计算机id
for (int i = 0; i < com.Length; i++)
{
com[i].ID = com[i].Type + "-" + num[i];
}
Console.WriteLine("************************设置计算机ID后*************************" + "\n");
foreach (computer item in com)
{
Console.WriteLine(item.Type + "\t\t" + item.ID + "\t" + item.Time);
}
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace instance
{
class computer
{
public string Type { get; set; }
public string Time { get; set; }
public string ID { get; set; }
public computer() { }
public computer(string TypeId, string BuyTime, string ID)
{
this.Type = TypeId;
this.Time = BuyTime;
this.ID = ID;
}
}
}