C# 构造函数属性
我想计算HRA、DA等。我必须定义一个构造函数,但是出现了一个错误,提到变量'basic_salary'已赋值,但从未使用过它的值 代码: 在C# 构造函数属性,c#,class,constructor,C#,Class,Constructor,我想计算HRA、DA等。我必须定义一个构造函数,但是出现了一个错误,提到变量'basic_salary'已赋值,但从未使用过它的值 代码: 在read()函数中,您再次定义basic_salary变量,而不是使用在班级级别定义的basic_salary 要解决您的问题,请尝试 public void read() { Console.WriteLine("Enter the employee name"); empname = Console.ReadLine
read()
函数中,您再次定义basic_salary
变量,而不是使用在班级级别定义的basic_salary
要解决您的问题,请尝试
public void read()
{
Console.WriteLine("Enter the employee name");
empname = Console.ReadLine();
Console.WriteLine("Enter the basic salary of an employee");
//insted of defining new integer as basic_salary, use existing class level basic_salary variable
basic_salary = Convert.ToInt32(Console.ReadLine());
calculate();
}
是的,谢谢,但当我输入基本工资为1000时,hra将为0,请也帮助我。由于
hra
的类型,您将获得0
。将HRA、DA、GS、incometax、netsalary的类型更改为双精度或十进制。好的,我编辑了上面的代码,对吗?好的,在阅读了上面的文章后,它通过将100改为100.0而工作了&其他的也很感谢
public void read()
{
Console.WriteLine("Enter the employee name");
empname = Console.ReadLine();
Console.WriteLine("Enter the basic salary of an employee");
//insted of defining new integer as basic_salary, use existing class level basic_salary variable
basic_salary = Convert.ToInt32(Console.ReadLine());
calculate();
}