C#不一致的可访问性错误
我很难用C#修复面向对象程序中的错误。该计划有9个班,在一个班。错误的可访问性不一致:参数类型“Employee.Employee”的可访问性不如方法“Employee.EmployeeInput.CollectEmployeeInfo(Employee.Employee)”的可访问性 关于编码C#不一致的可访问性错误,c#,C#,我很难用C#修复面向对象程序中的错误。该计划有9个班,在一个班。错误的可访问性不一致:参数类型“Employee.Employee”的可访问性不如方法“Employee.EmployeeInput.CollectEmployeeInfo(Employee.Employee)”的可访问性 关于编码 public static void CollectEmployeeInfo(Employee theEmployee) { theEmployee.Firstname
public static void CollectEmployeeInfo(Employee theEmployee)
{
theEmployee.Firstname = InputUtilities.getStringInputValue("First Name");
theEmployee.Lastname = InputUtilities.getStringInputValue("Last name");
theEmployee.Gender = InputUtilities.getCharInputValue("Gender");
theEmployee.Dependents = InputUtilities.getIntegerInputValue("# Dependents");
}
CollectEmployeeInfo是显示错误的内容,我不确定必须对其他类执行哪些操作才能修复错误。任何帮助都将不胜感激
class Employee
{
public const double MIN_SALARY = 20000;
public const double MAX_SALARY = 100000;
public const int MIN_DEPENDENTS = 0;
public const int MAX_DEPENDENTS = 10;
public const string DEFAULT_NAME = "not given";
public const char DEFAULT_GENDER = 'U';
public const string DEFAULT_TYPE = "Generic Employee";
protected string firstName;
protected string lastName;
protected double annualSalary;
protected char gender;
protected int dependents;
protected static int numEmployees = 0;
protected Benefits employeeBenefits;
protected string employeeType;
public Employee()
{
firstName = DEFAULT_NAME;
lastName = DEFAULT_NAME;
annualSalary = MIN_SALARY;
dependents = MIN_DEPENDENTS;
numEmployees++;
employeeBenefits = new Benefits();
}
public Employee(string firstname, string lastname, char gender, int dependents, double annualsalary, Benefits employeeBenefits)
{
Firstname = firstname;
Lastname = lastname;
AnnualSalary = annualsalary;
Gender = gender;
Dependents = dependents;
EmployeeBenefits = employeeBenefits;
numEmployees++;
}
public Benefits EmployeeBenefits
{
get { return employeeBenefits; }
set
{
if (value == null)
employeeBenefits = new Benefits();
else
employeeBenefits = value;
}
}
public Employee(string employeeType)
: this()
{
EmployeeType = employeeType;
}
public string Firstname
{
get { return firstName; }
set
{
if (String.IsNullOrEmpty(value))
firstName = DEFAULT_NAME;
else
firstName = value;
}
}
public string Lastname
{
get { return lastName; }
set
{
if (String.IsNullOrEmpty(value))
lastName = DEFAULT_NAME;
else
lastName = value;
}
}
public double AnnualSalary
{
get { return annualSalary; }
set
{
if (value > MIN_SALARY & value < MAX_SALARY)
annualSalary = value;
else if (value < MIN_SALARY)
annualSalary = MIN_SALARY;
else
annualSalary = MAX_SALARY;
}
}
public char Gender
{
get { return gender; }
set
{
if (value == 'F')
gender = value;
else if (value == 'f')
gender = value;
else if (value == 'M')
gender = value;
else if (value == 'm')
gender = value;
else
gender = DEFAULT_GENDER;
}
}
public int Dependents
{
get { return dependents; }
set
{
if (value >= MIN_DEPENDENTS & value <= MAX_DEPENDENTS)
dependents = value;
else if (value < MIN_DEPENDENTS)
dependents = MIN_DEPENDENTS;
else
dependents = MAX_DEPENDENTS;
}
}
public static int NumEmployees
{
get { return numEmployees; }
}
public string EmployeeName
{
get { return firstName + " " + lastName; }
}
public string EmployeeType
{
get { return employeeType; }
set
{
if (String.IsNullOrEmpty(value))
employeeType = DEFAULT_TYPE;
else
employeeType = value;
}
}
public double CalculatePay()
{
return annualSalary / 52;
}
public double CalculatePay(double modifiedSalary)
{
AnnualSalary = modifiedSalary;
return AnnualSalary / 52;
}
public override string ToString()
{
string output;
output = "\n============ Employee Information ============";
output += "\n\t Type:\t" + employeeType;
output += "\n\t Name:\t" + firstName + " " + lastName;
output += "\n\t Gender:\t" + gender;
output += "\n\t Dependents:\t" + dependents;
output += "\n\tAnnual Salary:\t" + annualSalary.ToString("C2");
output += "\n\t Weekly Pay:\t" + CalculatePay().ToString("C2");
output += "\n\t" + employeeBenefits.ToString();
return output;
}
}
class员工
{
公共建筑双最低工资=20000;
公共建筑双倍最高工资=100000;
public const int MIN_DEPENDENTS=0;
公共const int MAX_DEPENDENTS=10;
public const string DEFAULT_NAME=“未给定”;
公共常量字符默认值_性别='U';
public const string DEFAULT_TYPE=“Generic Employee”;
受保护的字符串名;
受保护的字符串lastName;
受保护的双年历;
性别保护;
受保护的受抚养人;
受保护的静态int numEmployees=0;
受保护的福利雇员福利;
受保护字符串employeeType;
公职人员()
{
firstName=默认名称;
lastName=默认名称;
年薪=最低工资;
受抚养人=最小受抚养人;
numEmployees++;
员工福利=新福利();
}
公共雇员(字符串firstname、字符串lastname、字符性别、int家属、双倍年薪、员工福利)
{
名字=名字;
Lastname=Lastname;
AnnualSalary=AnnualSalary;
性别=性别;
家属=家属;
员工福利=员工福利;
numEmployees++;
}
公共福利雇员福利
{
获取{return employeeBenefits;}
设置
{
如果(值==null)
员工福利=新福利();
其他的
员工福利=价值;
}
}
公共雇员(字符串employeeType)
:此()
{
EmployeeType=EmployeeType;
}
公共字符串名
{
获取{return firstName;}
设置
{
if(String.IsNullOrEmpty(value))
firstName=默认名称;
其他的
firstName=值;
}
}
公共字符串姓氏
{
获取{return lastName;}
设置
{
if(String.IsNullOrEmpty(value))
lastName=默认名称;
其他的
lastName=值;
}
}
公共双年历
{
获取{return annualSalary;}
设置
{
如果(价值>最低工资&价值<最高工资)
年平均值=价值;
否则如果(值<最低工资)
年薪=最低工资;
其他的
年工资=最高工资;
}
}
公共性别
{
获取{返回性别;}
设置
{
如果(值='F')
性别=价值;
else if(值='f')
性别=价值;
else if(值='M')
性别=价值;
else if(值='m')
性别=价值;
其他的
性别=默认性别;
}
}
公共受抚养人
{
获取{返回依赖项;}
设置
{
如果(value>=MIN_DEPENDENTS&valueEmployee
类型的可访问性不应低于CollectEmployeeInfo
因此Employee
应定义为public
“至少”需要传递给方法的所有类型必须至少与该方法一样可访问。如果Employee
是私有或内部类,则不能从该类/程序集外部传递给该方法
将Employee
设置为public,它应该可以工作。Employee类是public的,只有8个变量受保护,例如Firstname、Lastname、Gender和Dependents@Jess然后将Employee的代码复制到您原来的帖子并加以证明,因为您的错误是说它不是。@Jess如果您不指定,类默认为受保护的
。在类员工
前面添加public
,这应该可以解决问题。@thevilpenguin默认值是。你实际上不能将一个类标记为受保护的(除非它在另一个类中)@Jess,那么你必须编辑你的问题并告诉我们这些错误是什么。如果它们更“不易访问”错误您必须转到错误提到的类,并将这些类标记为公共类。此方法是否必须是静态的
?如果在类
前面没有任何内容,请不要编辑您的问题以提出新问题。打开一个新问题以执行此操作(你确实这么做了,但你也应该在这里把零钱退回来)。