score:10
Enumerable.OrderByDescending
if the problem was that you wanted descending and not ascending
score:4
If your talking about a generic IEnumerable, below is a trimmed down example of usage.
// Using complex type
class Person()
{
public string Name;
}
IEnumerable<Person> myEnumerable = new List<Person>();
this.myEnumerable.OrderByDescending(person => person.Name)
// Using value type
IEnumerable<int> ints = new List<int>();
ints.OrderByDescending(x => x);
score:5
If you mean a non-generic IEnumerable
, you should use Cast
or OfType
to get an IEnumerable<T>
first, then you can use the normal OrderBy
/ OrderByDescending
calls.
For example:
IEnumerable test = new string[] { "abc", "x", "y", "def" };
IEnumerable<string> orderedByLength = test.Cast<string>()
.OrderBy(x => x.Length);
You can also do this by explicitly stating the type in a query expression:
IEnumerable<string> orderedByLength = from string x in test
orderby x.Length
select x;
EDIT: Now that the question has been clarified, the query expression form is:
var query = from value in collection
orderby value.SomeProperty descending
select value;
Source: stackoverflow.com
Related Query
- how to order asc/dsc with lambda or linq
- How can anonymous types be created using LINQ with lambda syntax?
- Can you reverse order a string in one line with LINQ or a LAMBDA expression
- How to rewrite this LINQ using join with lambda expressions?
- LINQ - How to use distinct with order by?
- How do I simplify a LINQ query with multiple .Select() in order to return an IQueryable(int)
- How to use an expression with a generic func lambda in a linq where clause?
- How apply a method to all list members using very short linq with lambda omitted?
- How to swap the data source associated with a Linq query?
- How to order list in custom Item class with linq query
- ASP.NET MVC: How to use linq lambda expression with a ViewModel to get data?
- How to extract max(property) from left join in LINQ with lambda expression
- How to fix issue with group join in linq / lambda expression?
- How to order a collection with LINQ so that a particular string appears first
- How to merge two lists while adding metadata indicating value source with LINQ statement?
- How to find subsets with exact length using linq lambda syntax
- How can I make a Multiple property lambda expression with Linq
- How to LINQ DataTable with group by and order by to deduplicate data
- How to get dictinct userid with order by close using Linq
- How to Parse an XML file with Linq Lambda from Given Key
- how to write a Linq query with a EF code first Many to Many relationship
- Linq with lambda expression: how do IN statement from sql?
- How to write a LINQ query or Lambda expression on one to many relation with filter
- How to run Linq with order by and group by
- How to return same object with linq as with lambda
- How can I use order by and group by in Linq Extraction Method and With multiple data?
- How to substitute the LINQ Query with lambda expression
- How to convert linq expression with join to lambda expression?
- How can I order by more that one element with LINQ /
- How to use Linq or Lambda with IQueryable to GroupBy and get the first/last record on the collection in C#?
More Query from same tag
- Linq to Entites - Multiple columns search
- How to Bulk Update records in Entity Framework?
- Foreach item changes not preserved outside loop
- Can Linq retrieve rows from datagrid
- Linq Anonymous type members must be declared in Sub Query
- C# search a list using groupby and where
- Can't cast 'Newtonsoft.Json.Linq.JObject' to actual type
- Using linq to append list to list from select method
- Group by and Count result in LinQ
- Natural sort with Dynamic Linq including multiple sorting parameters
- Does converting an IEnumerable to IQueryable enumerate the query
- Issues in converting SQL to LINQ
- Unable to search with FirstOrDefault Method
- LINQ - database query using "into", how do I reference data prior to "into" in the select clause?
- Sort by Count Occurrences of a Word in list rows linq
- How to check if a string contains a particular string using linq?
- LinQ Order By on ViewBag
- The type arguments cannot be inferred from the usage
- Having trouble trying to order using linq
- how can I swap two child entity values
- Any way to find word in string without split
- Optional condition in join clause - Linq
- LINQ Query to Count Objects by Property Group Between Non Group Objects In Sequence
- Remove Single Quotes From All Cells in a DataTable - Creating New Table - Using LINQ in Vb.Net
- Can not Where-filter a query with multiple includes getting exception at runtime
- EntityFramework: Retrieve data with a condition on two different context
- Project a Type to class object by filtering out attributes using linq to xml
- Concat and/or merge objects in two generic lists
- Removing the WHERE clause in a Linq query
- How do I insert an element into XML using Linq?