변수 이름을 변경 했으므로 표시하지 않으려합니다.아무 것도 반환하지 않습니까?
업데이트 : 반환 방법 대신 변수로 바로 이동할 수 있습니다.
다음 문제를 해결하는 데 관심이 있으시면 계속하십시오.
그래서 나는이 하나 개의 클래스가 (이제를 ClassA를 가정 해 봅시다) : 다른 클래스에
string EmployeeName;
string EmployeePosition;
string PokemonPromotion;
int EmployeeSalary;
int EmployeeProductivity;
public EmployeeInformation(string name, string job, string promotion, int salary, int productivity)
{
EmployeeName = name;
EmployeePosition = job;
EmployeePromotion = promotion;
EmployeeSalary = salary;
EmployeeProductivity = productivity;
}
그리고이 (ClassB가를)
private EmployeeInformation[] Employee;
private int EmployeeAmount;
public Top()
{
Employee = new EmployeeInformation[100];
EmployeeAmount = 0;
}
public void HireEmployee(string name, string job, string promotion, int salary, int productivity)
{
Console.WriteLine("==HIRE PEOPLE==");
Employee[EmployeeAmount] = new EmployeeInformation(name, job, promotion, salary, productivity);
EmployeeAmount++;
}
내가 EmployeeName, EmployeePosition을 반환하는 방법을 만들었을 때, EmployeePromotion, EmployeeSalary 및 EmployeeProductivity는 아무 것도 반환하지 않습니다 (비어 있음). 미리 감사드립니다. 편집
: 여기
는 (방법이를 ClassA의 일부) 이 모두
public string ReturnEmployeeName()
{
return EmployeeName;
}
public string ReturnEmployeePosition()
{
return EmployeePosition;
}
public string ReturnEmployeePromotion()
{
return EmployeePromotion;
}
public int ReturnEmployeeSalary()
{
return EmployeeSalary;
}
public int ReturnEmployeeProductivity()
{
return Employee Productivity;
}
편집 2에 명확하게 희망 반환하는 방법은 다음과 같습니다이다 내가 수익을 테스트하려고 방법 . 여기에있는 아이디어는 for 루프의 모든 것을 나열하는 것입니다. 루프에 넣은 부분에 "0"을 교환합니다.
Employee[0].ReturnEmployeeName();
편집 3 : 이것은 내가 뭔가를 반환하는 경우 볼 수있는 방법을 만들 때이
public void ListEmployees()
{
Console.WriteLine("=LIST OF EMPLOYEES=");
Console.WriteLine("ID" + "\t"
+ "NAME" + "\t"
+ "POSITION" + "\t"
+ "PROMOTION" + "\t");
for (int i = 0; i < EmployeeAmount; i++)
{
Console.WriteLine("{0}", i + 1, "\t"
, Employee[i].ReturnEmployeeName(), "\t"
, Employee[i].ReturnEmployeePosition(), "\t"
, Employee[i].ReturnEmployeePromotion(), "\t");
}
}
(ClassB가에서) 루프 루프는하지만, 급여와 생산성을 인쇄하지 않습니다이다 나머지처럼 빈칸으로 돌아갑니다.
편집 4 : 내가 이것을 할 때마다 실제로 뭔가가 있습니다. 유일한 문제는 내가 그 방법을 사용할 때이다.
Console.WriteLine(Employee[0].EmployeeName);
이 실패한 메소드의 코드를 게시하지 않으면 어떻게 도와 드릴까요? – Steve
HireEmployee 메서드에서 EmployeeInformation을 반환하겠습니까? –
무엇이 문제입니까? 돌아 오지 않는 것은 무엇입니까? 대기, –