using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyID
{
class Computer
{
private string type;
public string Type
{
get { return type; }
set { type = value; }
}
private string id;
public string Id
{
get { return id; }
set { id = value; }
}
private string buyDate;
public string BuyDate
{
get { return buyDate; }
set { buyDate = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyID
{
class Manner
{
public void setID(Computer[] comps)
{
Random random = new Random();
foreach(Computer item in comps){
item.Id = item.Type + "-" + random.Next(1000,9999);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyID
{
class Program
{
static void Main(string[] args)
{
Manner myManner = new Manner();
Computer[] commputer = new Computer[3]{
new Computer(),
new Computer(),
new Computer()
};
commputer[0].Type = "hpCq-217Tx";
commputer[0].BuyDate = "2013-10-5";
commputer[1].Type = "Mc240CH/A";
commputer[1].BuyDate = "2014-11-11";
commputer[2].Type = "SYNW18H/w";
commputer[2].BuyDate = "2020-11-22";
Console.WriteLine("***********设置计算机ID前*************");
Console.WriteLine("计算机型号\t计算机ID\t购买时间");
foreach(Computer item in commputer)
{
Console.WriteLine("{0}\t{1}\t\t{2}",item.Type,item.Id,item.BuyDate);
}
Console.WriteLine("\n");
myManner.setID(commputer);
Console.WriteLine("***********设置计算机ID后*************");
Console.WriteLine("计算机型号\t计算机ID\t购买时间");
foreach(Computer item in commputer){
Console.WriteLine("{0}\t{1}\t{2}",item.Type,item.Id,item.BuyDate);
}
Console.ReadLine();
}
}
}