C#实现一个Person类,属性包含姓名年龄身份证号工作工资等,并显示各属性的值1)构造方法2)返回出生日期

2024-11-19 17:38:40
推荐回答(2个)
回答1:

using System;
namespace Person
{
class Person
{
string name, id, job;
int age;
double wage;
private Person(string name,int age,string id,string job,double wage)
{
this.name = name;
this.age = age;
this.id = id;
this.job= job;
this.wage = wage;
}
private void DisplayPerson()
{
Console.WriteLine("姓名:{0}\n年龄:{1}\n身份证号:{2}\n工作:{3}\n工资:{4} ", name, age, id, job, wage);
}
static void Main(string[] args)
{
Person p = new Person("小明", 20, "10023028", "会计",3000);
p.DisplayPerson();
Console.ReadLine();
}
}
}
我能说我认识你吗?哈哈

回答2:

public class Person
   {
       public DateTime Person(string Name ,string CardNo){
           return DateTime.Parse(Birthday.ToString("yyyy-MM-dd"));
       }
       public int ID { get; set; }
       public string Name { get; set; }
       public int Age{ get; set; }
       public string CardNo{ get; set; }
       public string Work{ get; set; }
       public double Salary{ get; set; }
          
       public DateTime Birthday{ get; set; }
   }