Home > Net >  A novice just contact with c # write a wage sorting practice please give directions
A novice just contact with c # write a wage sorting practice please give directions

Time:09-24

using System;
The namespace zz
{
Class Program
{
The static void Main (string [] args)
{
Var em=Sort (new Employee [] {new Employee (" a ", 71), a new Employee (" b ", 66), a new Employee (" c ", 761), a new Employee (78), "d"});
Foreach (var e in em)
{
Console. WriteLine (e.N ame + "wage is" + e.S alary. The ToString ());
}
}
The static Employee [] Sort (Employee [] the Employee)
{
Bool mark=true;
While (mark)
{
for(int i=0; I{
If (the employee [I] Salary> [I + 1]. The employee Salary)
{
Var temp=employee [I];
The employee [I]=employee [I + 1);
The employee [I + 1)=temp;
}
The else mark=false;
}
}
Return the employee;

}
}
The class Employee
{
Public string Name;
Public int Salary;
Public Employee (string name, int salary)
{
This. Name=Name;
This. Salary=Salary;
}
}
}

CodePudding user response:

Is there a more simple and concise way

CodePudding user response:

 
Var em=new Employee [] {new Employee (" a ", 71), a new Employee (" b ", 66), a new Employee (" c ", 761), a new Employee (78), "d"};
Em=em. OrderBy (e=& gt; E.S alary). ToArray ();

CodePudding user response:

Linq syntax look at: https://www.tutorialsteacher.com/linq/linq-sorting-operators-orderby-orderbydescending

CodePudding user response:

E=& gt; E.N ame
What is meaning of parameters is e, the return value is e.N ame a delegate?

CodePudding user response:

refer to the second floor Bridge_go response:
 
Var em=new Employee [] {new Employee (" a ", 71), a new Employee (" b ", 66), a new Employee (" c ", 761), a new Employee (78), "d"};
Em=em. OrderBy (e=& gt; E.S alary). ToArray ();


E=& gt; E.N ame
What is meaning of parameters is e, the return value is e.N ame a delegate?

CodePudding user response:

The
reference 3 floor exception92 response:
Linq syntax look at: https://www.tutorialsteacher.com/linq/linq-sorting-operators-orderby-orderbydescending

Collection thanks a lot,

CodePudding user response:

Class code and the main program code under the best separation, such as sort, in the class implementation is better,
  •  Tags:  
  • C#
  • Related