我知道在这里寻求家庭作业帮助是不受欢迎的,但我很难过。这是作业:
Employee 类 编写一个名为 Employee 的类,它具有以下属性:
- Name--Name 属性保存员工的姓名。
- IdNumber--IdNumber 属性保存员工的 ID 号。
- 部门--部门属性包含员工工作的部门的名称。
- Position-- Position 属性包含员工的职位。
该类应具有以下重载构造函数: 接受以下值作为参数并将它们分配给适当属性的构造函数:员工姓名、员工 ID 号、部门和职位。构造函数接受以下值作为参数并将它们分配给适当的属性:员工姓名、员工 ID 号、部门和职位属性应分配空字符串 ("") 分配空字符串 (") 的无参数构造函数") 到 Name、Department 和 Position 属性,0 到 IdNumber 属性。
在应用程序中,创建三个 Employee 对象来保存以下数据:
Name Id Number Department Position
----------- ---------- ---------- ---------
Susan Meyers 47899 Accounting Vice President
Mark Jones 39119 IT Programmer
Joy Rogers 81774 Manufacturing Engineer
应用程序应将此数据存储在三个对象中,并在屏幕上显示每个员工的数据。
这是我的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EMp
{
public partial class Form1 : Form
{
const int SIZE = 3;
Employee[] theEmployee = new Employee[SIZE];
public Form1()
{
InitializeComponent();
}
class Employee
{
public string _Name;
public string _IdNumber;
public string _Department;
public string _Position;
public Employee(string Name, string IdNumber, string Department, string Position)
{
_Name = Name;
_IdNumber = IdNumber;
_Department = Department;
_Position = Position;
}
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public string IdNumber
{
get { return _IdNumber; }
set { _IdNumber = value; }
}
public string Department
{
get { return _Department; }
set { _Department = value; }
}
public string Position
{
get { return _Position; }
set { _Position = value; }
}
}
private void Form1_Load(object sender, EventArgs e)
{
theEmployee[0] = new Employee("Susan Meyers", "47899", "Accounting", "Vice President");
theEmployee[1] = new Employee("Mark Jones", "39119", "IT", "Programmer");
theEmployee[2] = new Employee("Joy Rogers", "81774", "Manufacturing", "Enginner");
}
private void btnDisplay_Click(object sender, EventArgs e)
{
lblName1.Text = theEmployee[0]._Name;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
当我单击显示时,没有任何反应。所以我真的不确定它是否有效,或者我试图显示它的方式是否是错误的。我也不确定是否可以显示整个内容,或者我是否必须执行 lblName1.Text = theEmployee[0]._IdNumber; 以及其他所有内容都在其自己的显示标签中。