score:14
try this snippet:
var sortedvalues = values
.orderbydescending(x => x.length)
.thenbydescending(x => convert.toint32(x));
if you really need use it as a list, then add tolist()
at the end.
score:2
values.orderbydescending(x => x.length).thenbydescending(x => int.parse(x));
score:3
most of the answers here are written using lambda syntax, if you want query syntax try this. result should be the same.
var sortedvalues = from x in values
orderby x.length descending, x descending
select x;
score:4
i'm going to assume you actually care about the value of each integer. if so:
var sortedvalues = values.orderbydescending(x => x.length)
.thenbydescending(x => int.parse(x));
this will yield a deferred iorderedenumerable<string>
. the int.parse
is only for the purpose of secondary ordering. if you need to materialize it, toarray
or tolist
will need to be called.
Source: stackoverflow.com
Related Query
- How to use Linq to sort an array by Length and then value
- How can define a 26x2 array and then use LINQ on its rows?
- How to assign LINQ Query to a variable and then use it later in the code
- Linq query, how to check for a null value and use the value 0 in place of a null?
- How to use a LINQ in order to remove Min and Max value in List
- How can I use LINQ to filter and sort rows from one collection to another?
- How to get 0 out of a null linq query value when a condition isn't met and then set it to a ViewBag
- how do i convert Dictionary string string to array of key value pair of string and string using linq and c#
- How to use a LINQ : If there are several min and max values, just remove only one min and max value in List
- How do I use LINQ to access a specific value from of an array of JObjects that seems to be stored in a string
- How to find out if one element in array has false value for property and if all elements have true value using Linq
- Use LINQ to select from, and sort a 2D array
- How to use LINQ to group by one field, sort within that grouping, and sum values for that combination?
- How to sort by a specific key and then get the first result in the sorted collection into a group in LINQ
- Linq how to union array of objects inside list and group by value
- List of objects where the object contains an array - how to use LINQ to search through all objects for a value in that array
- How to use Linq on IList, to compare first value and second value present on the list based on some conditions.?
- How to use linq to split a list of objects by half and then group them
- Iterate over array with LINQ and use the value at each position
- How to add single quotes for string value of dynamic query string and use it in linq
- How to get a value of a column name in C# / Linq and then place the values in your own class
- How to use LINQ to select object with minimum or maximum property value
- How can I use linq to sort by multiple fields?
- How to use LINQ on a multidimensional array to 'unwind' the array?
- How to get a byte array length using LINQ to Entities?
- How can I use linq to initialize an array of repeated elements?
- How to use IEnumerable.Cast<> and .ToArray() to convert int array to an enum array?
- How can I use LINQ to project this parent and children object model into a flat, single object?
- Linq group string array by count and sort
- How do I use an array of values in a LINQ Expression builder?
More Query from same tag
- How to create a breadcrumb for categories and subcategories using linq
- MVC 5 - Order by MAX() using LINQ
- Linq XML complex select (3 levels)
- How to use join in linq query?
- Take value from part of a LINQ query and add it to the result
- linq and string.compare/string.equals in wcf?
- The entity or complex type 'SJAMsSynchMetroModel.tblActionItem' cannot be constructed in a LINQ to Entities query
- C# dynamic predicate building
- Retrieve index of a List<> item based in C# using Linq
- C#: Remove duplicate values from dictionary?
- LinQ DataTable Group By
- The text data type cannot be selected as DISTINCT because it is not comparable
- How to get items of an entity's collection property using Linq?
- Filtering data from DB
- Is output of Extension Method IEnumerable.Average() wrong for some values?
- adding where clauses to linq query
- winforms datagridview sorting using LINQ
- How to create more complex models from many tables in asp.net mvc, linq
- capture any aliphatic on keyboard while form is not visible?
- Use contains in LINQ to SQL join
- Get average salary for department (ASP.NET)
- SQL to LINQ Involving Multiple GroupJoin
- problem with linq (C#)
- Remove records from 1 query based on same values found in another query
- Improving O(n^2) algorithm
- How to Get this ID
- Pivot-table-esque result using LINQ
- Pivot list data using LINQ
- Inner join not working when use equal with %, What an alternative way to use it like like %
- How to create this Linq function?