呵呵,刚看了视频,想总结写了个人类,大家帮着看看,完善完善- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace 调试人类
- {
- class Program
- {
- static void Main(string[] args)
- {
- PersonMessage message = new PersonMessage();
- Person onePerson = new Person(message);
- onePerson.GetMessage("王1虎", Sex.男, 23, Profession.程序员);
- onePerson.GetMessage("王2虎", Sex.男, 23, Profession.程序员);
- onePerson.GetMessage("王2虎", Sex.男, 23, Profession.程序员);
- //问题是怎么解决信息相同的问题,集合中有没有解决的方法
- onePerson.sayHi(0);
- onePerson.sayHi(1);
- onePerson.sayHi(2);
- Console.ReadKey();
- }
- }
- }
复制代码- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace 调试人类
- {
- //这里我定义了两个枚举变量
- public enum Sex { 男, 女 }
- public enum Profession { 学生, 教师, 程序员 }
- //这里我定义了个结构封装个人信息
- public struct PersonMessage
- {
- string name;
- Sex sex;
- int age;
- Profession profession;
- public string Name { get { return name; } }
- public Sex Sex { get { return sex; } }
- public int Age { get { return age; } }
- public Profession Profession { get { return profession; } }
- public PersonMessage(string myName, Sex mySex, int myAge, Profession myprofession)
- {
- name = myName;
- sex = mySex;
- age = myAge;
- profession = myprofession;
- }
- }
复制代码 |