c# 根据提供的员工类,定义三个版本的构造函数,版本一根据参数初始化工号、姓名,性别为男,工资为1200;版本二根据参数初始化工号、姓名、性别,工资为1200;版本三根据参数初始化工号、姓名、性别和工资。使用三个版本的构造函数创建三个对象,并分别输出工号验证初始化的字段值。用C#语言怎么编写?急!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class Person { string worknum; string name; string sex; float salary; public Person(string _worknum,string _name) { this.worknum = _worknum; this.name = _name; this.sex = "男"; this.salary = 1200; } public Person(string _worknum, string _name,string _sex) { this.worknum = _worknum; this.name = _name; this.sex = _sex; this.salary = 1200; } public Person(string _worknum, string _name, string _sex,float _salary) { this.worknum = _worknum; this.name = _name; this.sex = _sex; this.salary = _salary; } }实例就通过这三个构造函数去做 class yuangong{ int yuangonghao; string xingming; string xingbie = "男"; int gongzi=1200;public yuangong(int yuangonghao1,string xingming1) {yuangonghao = yuangonghao1;xingming=xingming1; } public yuangong(int yuangonghao1,string xingming1,string xingbie1) {yuangonghao = yuangonghao1;xingming=xingming1;xingbie=xingbie1; } public yuangong(int yuangonghao1,string xingming1,string xingbie1,int gongzi1) {yuangonghao = yuangonghao1;xingming=xingming1;xingbie=xingbie1;gongzi=gongzi1; }} static void Main(string[] args) { Employee e1 = new Employee(1, "John"); Console.WriteLine(e1.No); Employee e2 = new Employee(2, "Smith", "男"); Console.WriteLine(e2.No); Employee e3 = new Employee(3, "Paul", "男", 2400); Console.WriteLine(e3.No); } public class Employee { public int No { get; set; } public string Name { get; set; } public string Sex { get; set; } public double Salary { get; set; } public Employee(int no, string name, string sex, double salary) { this.No = no; this.Name = name; this.Sex = sex; this.Salary = salary; } public Employee(int no, string name, string sex) : this(no, name, sex, 1200) { } public Employee(int no, string name) : this(no, name, "男", 1200) { } } public class Person { string worknum; string name; string sex; float salary; public Person(string _worknum, string _name) { this.worknum = _worknum; this.name = _name; this.sex = "男"; this.salary = 1200; } public Person(string _worknum, string _name, string _sex) { this.worknum = _worknum; this.name = _name; this.sex = _sex; this.salary = 1200; } public Person(string _worknum, string _name, string _sex, float _salary) { this.worknum = _worknum; this.name = _name; this.sex = _sex; this.salary = _salary; } public override string ToString() { return string.Format("worknum:{0},name:{1},sex:{2},salary:{3}", this.worknum, this.name, this.sex, this.salary); } } class Program { static void Main(string[] args) { Person person0 = new Person("123", "kk"); Console.WriteLine( person0.ToString()); Person person1 = new Person("123", "kk","mm"); Console.WriteLine( person1.ToString()); Person person2 = new Person("123", "kk","mm",1234); Console.WriteLine( person2.ToString()); Console.ReadKey(); } } webBrowser 获取页面元素问题 C# esc/p字体放大 求解决方法? 点击GridView中的按钮’ 窗体根据数据库里的信息初始化 DataGridView手动设置列后,无法显示水平滚动条 C#中 请问怎么将一个byte[] 数组转化为string 对象? 谢谢 如何编写一个winform的含有DataGrid的自定义控件 急救啊!!!!!!!!!!!!动态添加一DropDowenList控件,并且给这个控件添加一个SelectIndexChange事件 如何重载窗口标题栏的双击消息处理函数? 您的请求来路不正确 post 高手求解
public class Person
{
string worknum;
string name;
string sex;
float salary;
public Person(string _worknum,string _name)
{
this.worknum = _worknum;
this.name = _name;
this.sex = "男";
this.salary = 1200;
}
public Person(string _worknum, string _name,string _sex)
{
this.worknum = _worknum;
this.name = _name;
this.sex = _sex;
this.salary = 1200;
}
public Person(string _worknum, string _name, string _sex,float _salary)
{
this.worknum = _worknum;
this.name = _name;
this.sex = _sex;
this.salary = _salary;
}
}实例就通过这三个构造函数去做
{
int yuangonghao;
string xingming;
string xingbie = "男";
int gongzi=1200;
public yuangong(int yuangonghao1,string xingming1)
{
yuangonghao = yuangonghao1;
xingming=xingming1; } public yuangong(int yuangonghao1,string xingming1,string xingbie1)
{
yuangonghao = yuangonghao1;
xingming=xingming1;
xingbie=xingbie1; } public yuangong(int yuangonghao1,string xingming1,string xingbie1,int gongzi1)
{
yuangonghao = yuangonghao1;
xingming=xingming1;
xingbie=xingbie1;
gongzi=gongzi1; }}
static void Main(string[] args)
{
Employee e1 = new Employee(1, "John");
Console.WriteLine(e1.No);
Employee e2 = new Employee(2, "Smith", "男");
Console.WriteLine(e2.No);
Employee e3 = new Employee(3, "Paul", "男", 2400);
Console.WriteLine(e3.No);
} public class Employee
{
public int No { get; set; }
public string Name { get; set; }
public string Sex { get; set; }
public double Salary { get; set; } public Employee(int no, string name, string sex, double salary)
{
this.No = no;
this.Name = name;
this.Sex = sex;
this.Salary = salary;
} public Employee(int no, string name, string sex)
: this(no, name, sex, 1200)
{ } public Employee(int no, string name)
: this(no, name, "男", 1200)
{ }
}
public class Person
{
string worknum;
string name;
string sex;
float salary;
public Person(string _worknum, string _name)
{
this.worknum = _worknum;
this.name = _name;
this.sex = "男";
this.salary = 1200;
}
public Person(string _worknum, string _name, string _sex)
{
this.worknum = _worknum;
this.name = _name;
this.sex = _sex;
this.salary = 1200;
}
public Person(string _worknum, string _name, string _sex, float _salary)
{
this.worknum = _worknum;
this.name = _name;
this.sex = _sex;
this.salary = _salary;
}
public override string ToString()
{
return string.Format("worknum:{0},name:{1},sex:{2},salary:{3}", this.worknum, this.name, this.sex, this.salary);
}
}
class Program
{
static void Main(string[] args)
{
Person person0 = new Person("123", "kk");
Console.WriteLine( person0.ToString());
Person person1 = new Person("123", "kk","mm");
Console.WriteLine( person1.ToString());
Person person2 = new Person("123", "kk","mm",1234);
Console.WriteLine( person2.ToString());
Console.ReadKey();
}
}