#csharp #linq
LINQ supports multiple fields in
---
### Example: Equivalent of
---
### Explanation:
-
-
Each
LINQ supports multiple fields in
OrderBy
, just like SQL's ORDER BY A DESC, B ASC
.---
### Example: Equivalent of
ORDER BY A DESC, B ASC
in LINQvar sorted = data
.OrderByDescending(x => x.A)
.ThenBy(x => x.B);
---
### Explanation:
-
OrderBy
/ OrderByDescending
sets the primary sort.-
ThenBy
/ ThenByDescending
adds secondary, tertiary, etc., sorts.Each
ThenBy
applies only if the previous key values are equal—just like in SQL.