CodePudding user response:
The teacher's requirements:
using System;
The namespace Study {
Class Program {
The static void Main () {
String [] name=new string [5].
Int [] or=new int [5].
For (int I=0; i <5; I++) {
Console. WriteLine (" first "+ I + 1 +" employee information: ");
The Console. Write (" name: ");
The name [I]=Console. ReadLine ();
The Console. Write (" salary: ");
Or [I]=int. Parse (the Console. The ReadLine ());
}
Console. WriteLine (" please enter to view the employee number: ");
Int num=int. Parse (Console. ReadLine ());
Show (the name [num 1], or [] num - 1);
}
The static void Show (string n, int m) {
To the Console. WriteLine (n + "annual salary" + m * 12);
}
}
}
Actual demand more normal writing:
using System;
using System.Collections.Generic;
The namespace Study {
Class Program {
The static void Main () {
HumanResource hr=new HumanResource ();
For (int I=0; i <5; I++) {
Console. WriteLine ($" first {I + 1} employee information: ");
The Console. Write (" name: ");
string name=Console.ReadLine();
The Console. Write (" salary: ");
Int or=int. Parse (Console. ReadLine ());
Hr. The Add (name, or);
}
Console. WriteLine (" please enter to view the employee number: ");
Int num=int. Parse (Console. ReadLine ());
Hr. The Show (num - 1);
}
}
The class HumanResource {
Private ListHumans=new List (a);
Public void the Add (string name, int or) {
Humans. The Add (new Human {Name=Name, or=or});
}
Public void Show (int num) {
Console. WriteLine (${" humans [num]. Name} the salary of {humans [num] or * 12} ");
}
}
The class the Human {
Public string Name {get; set; }
Public int or {get; set; }
}
}
CodePudding user response:
The namespace Example
{
Class Program
{
The static void Main (string [] args)
{
String [] nameArray=new string [5] {" li bai ", "high gradually from", "cheng jin", "Angela", "production"};
Int [] salaryArray=new int [5] {8220, 7800, 6800, 5600, 8400};
For (int I=1; i <=5; I++)
{
String name=nameArray [I - 1);
Int salary=salaryArray [I - 1);
Console. WriteLine (" {0} employee information: \ n name: {1} \ n pay: {2} ", I, name, salary).
}
Console. WriteLine (" please enter to view the employee number: ");
Int num=the Convert. ToInt32 (Console. ReadLine ());//try-catch
String nameStr=nameArray [num 1];
Int salaryStr=salaryArray [num 1];
PrintResult (nameStr salaryStr);
}
The static void PrintResult (string name, int salary)
{
Console. WriteLine (" {0} a salary of {1} ", name, salary * 12);
}
}
}