• 上机练习2 生成计算机ID


    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();
            }
           
        }
    }

  • 相关阅读:
    Python全栈开发——装饰器
    Python全栈开发——类
    Python全栈开发——Json & pickle & shelve & sys模块
    Python全栈开发——正则表达式
    实验3- 熟悉常用的 HBase 操作
    Hbase PleaseHoldException错误
    HDFS 中文件操作的错误集锦
    ubuntu在虚拟机下的安装 ~~~ Hadoop的安装及配置 ~~~ Hdfs中eclipse的安装
    假期周进度报告---08
    假期周进度报告---07
  • 原文地址:https://www.cnblogs.com/1234wwww/p/6524637.html
Copyright © 2020-2023  润新知