score:11
Accepted answer
Update: Thanks @JeppeStigNielsen for correct comment, I add StringComparer.Ordinal
to support in all cultures:
var result = List.OrderBy(p=>p.Length).ThenBy(p=>p,StringComparer.Ordinal);
score:3
First order by the length of column name ("C" comes before "AB"), then use normal alphabetical (string) sorting on strings with same length ("AC" before "AD").
var columns = new[] { "A", "C", "AB", "AD", "N", "Z", "AC" };
var sorted = columns.OrderBy(c => c.Length)
.ThenBy(c => c);
Source: stackoverflow.com
Related Articles
- Sort List<string> like Excel columns sort
- Allow user to sort columns from a LINQ query in a DataGridView
- sort columns of gridview in asp.net c#
- C# DataTable select columns where column name like
- LINQ Source Code Available
- .NET 4 Code Contracts: "requires unproven: source != null"
- How to export linq result to excel just like Linqpad
- C#: Adding Columns To Bound DatagridView With Code
- creating Linq to sqlite dbml from DbLinq source code
- How to get columns from the excel generated using EPPLUS
- Sort a string property like Integer LINQ
- C# SQL/Linq/Entity Framework calculating column totals for multiple columns from large data source
- source code for LINQ 101 samples
- Sort List with two parameters but in different lines of code
- Linq sort by 2 columns with FirstOrDefault
- LINQ Sort DataTable based on 2 columns
- How to sort list on multiple properties in one line of code in Linq
- Linq query to sort strings like numbers in ASP.NET-Core 3.0 and above
- Linq Sort by 2 Columns (Created and Modified) whichever is greater
- map one to one with multiple primary key columns entity framework code first
- I have a list of countries. I'd like to sort it alphabetically, except for two countries which I'd like to put first
- I would like others to explain this piece of code to me
- How sort generic list like datatable in c#
- sort a list to be just like another list
- How can I allow user to sort columns on a LINQ-to-SQL WPF Datagrid?
- List or Array of String Contain specific word in Html Source Code
- new to linq. compiler doesnt like my query. Code provided
- how to sort an anonymous type without named columns
- Query Excel where Rows and Columns are reversed
- LINQ Select mutiply columns as data source for combobox C#
- linq distinct or group by multiple properties
- Hierarchical select in Entity Framework with lambda expression
- Linq query where clause
- Entity Framework: LINQ query generates different SQL between local execution and server execution
- Pass an IO.DirectoryInfo property as a parameter to a function?
- return biggest value from query
- linq query on multiple columns from a list of objects
- How can apply TryParse on multiple propertied with fluent LINQ?
- Using Lambda with Dictionaries
- Sort List by date values
- How to write that special select query
- How can I use be generic to result of linq query?
- lambda expression with nullable value - always false since the value of type Guid is never equal to 'null'
- ArgumentOutOfRangeException when replacing items in an ObservableCollection<T>
- orderby () containing numbers and letters
- LinqDataSource_Selecting does not work
- Parse certain data using JSON.Net
- C# LINQ with XML, cannot extract multiple fields with same name into object
- Linq Expression Chain Syntax for In Query
- Processing lambda query result in C# after performing table join