c#oop第二章上机2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace chapter02
{
class Menu
{
public static void Main(string[] args)
{
//初始化对象
Computer[] com = new Computer[3];
Computer com1 = new Computer();
com1.Type = “hpCQ-217TX”;
com1.BuyDate = “2013-10-5”;
com[0] = com1;
Computer com2 = new Computer();
com2.Type = “Mc240CH/A”;
com2.BuyDate = “2013-10-5”;
com[1] = com2;
Computer com3 = new Computer();
com3.Type = “SYNW18H/W”;
com3.BuyDate = “2013-10-5”;
com[2] = com3;
Console.WriteLine(“设置计算机ID前***”);
Console.WriteLine(“计算机型号\t计算机ID\t购买时间”);
for (int i = 0; i < com.Length; i++)
{
Console.WriteLine("{0}\t\t\t{1}",com[i].Type,com[i].BuyDate);
}

        Console.WriteLine("加上计算机id后");
        Ran rr = new Ran();
        rr.getid(com);

        Console.WriteLine("***************设置计算机ID后******************");
        Console.WriteLine("计算机型号\t计算机ID\t购买时间");
        for (int i = 0; i < com.Length ; i++)
        {
            Console.WriteLine("{0}\t{2}\t\t{1}", com[i].Type, com[i].BuyDate,com[i].ID);
        }
    }
}

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace chapter02
{
public class Ran
{
public void getid(Computer[] com)
{
Random rand = new Random();

        for (int i = 0; i < com.Length; i++)
        {
            com[i].ID = com[i].Type + "-" + rand.Next(1000, 9999);
            int a = rand.Next(1000,10000);
        }
    }
}

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace chapter02
{
public class Computer
{
public string Type;//型号
public string ID;//id
public string BuyDate;//购买日期

}

}

猜你喜欢

转载自blog.csdn.net/Ccccccccyq/article/details/113001818
今日推荐