傻瓜先生DIM 2019-04-13 11:48 采纳率: 100%
浏览 1364
已结题

C#测试类怎么写 (急用)???

求C#的测试类(急用)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program
{
    enum Sexkind { Male, Female }
    class Human
    {
        private string no;
        public string No
        {
            get { return no; }
            set
            {

                int y = int.Parse(no.Substring(0, 4));
                if (no == null || no.Length != 12)


                    throw new Exception("长度不到十二位");
                else if
                    (y > DateTime.Now.Year || y < DateTime.Now.Year - 100)
                    throw new Exception("年份错误");
                else
                    no = value;
            }
        }
        public string Name { set; get; }
        public Sexkind Sex { set; get; }
        public int count { set; get; }
        public int Year
        {
            get { return int.Parse(no.Substring(0, 4)); }
        }

        public string Info
        {
            get { return No + "\t" + Name + "\t" + Sex; }
        }
        public Human()
        {
            count++;
        }
        public Human(string no, string name, Sexkind sex)
        {
            count++;
            No = no;
            Name = name;
            Sex = sex;
        }
        public void Show()
        {
            Console.WriteLine(Info);
        }
        public void SayHello()
        {
            Console.WriteLine("Hello, human!");
        }
        public delegate void State(object sender, string message);
        public event State OnIdle;
        public event State OnWork;

        static void Main(string[] args)
        {
            Human hu = new Human("201902211122", "哇哈哈", Sexkind.Male);
            hu.Show();
            hu.SayHello();



        }
    }
}

}

  • 写回答

2条回答

  • threenewbee 2019-04-13 11:53
    关注
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Q756552
    {
        class Human
        {
            private string no;
            public string No
            {
                get { return no; }
                set
                {
                    no = value;
                    int y = int.Parse(no.Substring(0, 4));
                    if (no == null || no.Length != 12)
                        throw new Exception("长度不到十二位");
                    else if
                        (y > DateTime.Now.Year || y < DateTime.Now.Year - 100)
                        throw new Exception("年份错误");
                }
            }
            public string Name { set; get; }
            public Sexkind Sex { set; get; }
            public static int count { set; get; }
            public int Year
            {
                get { return int.Parse(no.Substring(0, 4)); }
            }
    
            public string Info
            {
                get { return No + "\t" + Name + "\t" + Sex; }
            }
            public Human()
            {
                count++;
            }
            public Human(string no, string name, Sexkind sex)
            {
                count++;
                No = no;
                Name = name;
                Sex = sex;
            }
            public void Show()
            {
                Console.WriteLine(Info);
            }
            public void SayHello()
            {
                Console.WriteLine("Hello, human!");
            }
            public delegate void State(object sender, string message);
            public event State OnIdle;
            public event State OnWork;
    
            public void DoWork()
            {
                if (OnWork != null)
                    OnWork(this, "I am working");
            }
        }
    
        enum Sexkind { Male, Female }
    
        class Program
        {
    
            static void Main(string[] args)
            {
                Human hu = new Human("201902211122", "哇哈哈", Sexkind.Male);
                hu.SayHello();
                hu.Show();
                hu.OnWork += new Human.State(hu_OnWork);
                hu.DoWork();
                Console.WriteLine(hu.Info);
                Human hu1 = new Human();
                Console.WriteLine(Human.count);
            }
    
            static void hu_OnWork(object sender, string message)
            {
                Console.WriteLine("the work says: " + message);
            }
        }
    }
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 镍氢电池充电器设计实物使用原理
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号