Lambda表达式,用于对集合列表进行排序

时间:2018-12-06 04:42:17

标签: c# .net linq lambda

我的输入是在xml文件下面

<?php
require "Constants.php"; 
 if($_SERVER['REQUEST_METHOD'] == 'POST')
 {
  $DefaultId = 0;
  $image = $_POST['image'];
 $mobile = $_POST['mobile'];
// if(isset($_POST['image']))
//{ 
 $ImagePath = "imageUploads/$mobile.jpg";
 $ServerURL = "yourPath/$ImagePath";
 $InsertSQL = "INSERT INTO info (img) values('$ServerURL') where 
mobile=$mobile";
 if(mysqli_query($conn, $InsertSQL)){
 file_put_contents($ImagePath,base64_decode($ImageData));
 echo "Your Image Has Been Uploaded.";
mysqli_close($conn);
 }
 else{
 echo "Please Try Again";
 }
//}
}
?>

我已经添加了以下代码,但是它要么明智地返回“位置”,要么明智地返回“否”,但不会同时返回。

<Employees>
  <Department Position="9">
   <Employee No="7" Status="True" />
   <Employee No="6" Status="True" />
   <Employee No="8" Status="True" />
</Department>
<Department Position="4">
  <Employee No="7" Status="True" />
  <Employee No="8" Status="True" />
  <Employee No="6" Status="True" />
</Department>
</Employees>

Out put should  be  sorted  by department position  and  employee  "No"


<Employees>
 <Department Position="4">
  <Employee No="6" Status="True" />
  <Employee No="7" Status="True" />
  <Employee No="8" Status="True" />
 </Department>
 <Department Position="9">
   <Employee No="6" Status="True" />
   <Employee No="7" Status="True" />
   <Employee No="8" Status="True" />
 </Department>  

3 个答案:

答案 0 :(得分:4)

sortSignalList.OrderBy(x => x.Position).ThenBy(x=>x.No).ToList();

答案 1 :(得分:0)

尝试。...

sortSignalList.OrderBy(x => x.Position).ThenBy(x=>x.No).ToList()

答案 2 :(得分:0)

列表也可以排序 ThenByDescending

var thenByDescResult =sortSignalList.OrderBy(s => s.Position).ThenByDescending(s => s.No);