这是我的作业,我在让我的课与main一起工作时遇到了麻烦,有人能帮帮我吗,这将于周二到期,我尝试的每一种方法都碰壁了。我所有的课和表格都贴出来了。请帮帮我,我完全迷路了,很沮丧1.员工和生产工人类别
创建一个Employee类,该类具有以下数据的属性:•员工姓名•员工编号
接下来,创建一个名为ProductionWorker的类,该类派生自Employee类。
ProductionWorker类应该具有用于保存以下数据的属性:•移位号(整数,如1、2或3)•小时工资率工作日分为两个班次:白天和晚上。
Shift属性将包含一个整数值,表示员工工作的班次。白班是1班,夜班是2班。
创建一个应用程序,该应用程序创建ProductionWorker类的对象,并允许用户为该对象的每个属性输入数据。检索对象的属性并显示其值。
这是我的员工参考资料表。为了存储他们的名字和ID数字,我在这个类上没有遇到编译错误,但我不确定我是否做得正确,因为我主要遇到了编译错误。
我想我需要一个数组来存储将在视觉中输入到我的TextBox中的所有数据
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Employee_References
{
class Roster
{
// Field for name, ID, dept, and position
private const int NAMES = 100;
private static string [] employee = new string [NAMES];
private const int NUMBER = 100;
private static int [] id = new int [NUMBER];
private int total = 0;
public void Employee()
{
total = 0;
}
// This will recieve input from my main
public static void employeeName (string [] xArray)
{
for (int index = 0; index < xArray.Length; index++)
{
xArray[index] = employee[NAMES];
}
}
// This will recieve input from my main
public static void idNumber ( int [] zArray)
{
for (int index = 0; index < zArray.Length; index++)
{
zArray[index] = id[NUMBER];
}
}
}
}
这将是我的下一节课,根据我的作业要求,从我的第一节课派生而来。假设这个类存储4的班次编号1到,以及白班和夜班的小时工资设置器。我在这个类中遇到一个编译错误,上面写着"赋值的左侧必须是变量、属性或索引器"。我不确定它在告诉我什么,有人能解释一下它试图告诉我什么吗?我做得对吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Employee_References
{
class References : Roster
{
// Field for name, ID, dept, and position
private int shift;
private static const double PAYRATEDAY = 12.75;
private static const double PAYRATENIGHT = 15.75;
public void Employee()
{
}
// This will recieve input from my main
public int shifts
{
set {shift = value;} // this set the recieve value of name one and set it to name1
get {return shift; } //this will get name1 and send it to my main.
}
// This will recieve input from my main
public double payrate1
{
set { PAYRATEDAY = value; } // ERROR!!The left-hand side of an assignment must be a variable, property or indexer
get { return PAYRATEDAY; }
}
// This will recieve input from my main
public double payrate2
{
get { return PAYRATENIGHT; } // ERROR!!The left-hand side of an assignment must be a variable, property or indexer
set { PAYRATENIGHT = value; }
}
}
这是我的Form,我正试图将我的输入值发送到我的类中——我的"Roster"类,它有一个100的数组。我总是收到一个编译错误,上面写着"无法分配给‘employeeName’,因为它是一个‘方法组’"。我不确定它告诉我的是什么,有人能向我解释这一点,并给我一些关于如何进行的指导吗
using System;
using System.Windows.Forms;
namespace Employee_References
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Roster Chart = new Roster();
Chart.employeeName = name.Text; // Error **Cannot assign to 'employeeName' because it is a 'method group**".
}
}
}
employeeName()是一个方法,您正试图为它赋值。
看起来你想尝试将一个名称数组作为参数传递给它
//first define and populate myArray
Chart.employeeName(myArray)
你说
private static const double PAYRATEDAY = 12.75;
然后
public double payrate1
{
set { PAYRATEDAY = value; } // ERROR!!The left-hand side of an assignment must be a variable, property or indexer
get { return PAYRATEDAY; }
}
如果要更改字段常量,为什么要声明它?
此外,我认为最好使用列表而不是数组,这样它就可以根据需要动态增长,而不是受到固定数量的限制。