Very easy with LINQ.
To sort by name,
var sorted = Directory.GetFiles(".").OrderBy(f => f);
To sort by size,
var sorted = Directory.GetFiles(".").OrderBy(f => new FileInfo(f).Length);
More Related Contents:
- How to Sort a List by a property in the object
- Preserving order with LINQ
- UnauthorizedAccessException cannot resolve Directory.GetFiles failure [duplicate]
- Alphanumeric sorting using LINQ
- C# List Sort by x then y
- How do I sort strings alphabetically while accounting for value when a string is numeric?
- Simple bubble sort c#
- How to sort a list of objects by a specific field in C#?
- How do I sort a two-dimensional (rectangular) array in C#?
- String sorting issue in C#
- Sorting an IList in C#
- Sorting an array of folder names like Windows Explorer (Numerically and Alphabetically) – VB.NET
- sort string-numbers [duplicate]
- Retrieving files from directory that contains large amount of files
- Sorting a Dictionary in place with respect to keys
- Sort a Custom Class List
- How do I implement automatic sorting of DataGridView?
- Memory-constrained external sorting of strings, with duplicates combined&counted, on a critical server (billions of filenames)
- The data source does not support server-side data paging
- LINQ Custom Sort
- How would I sort a list of files by name to match how Windows Explorer displays them?
- C# list.Orderby descending
- List complex sorting
- How to sort two arrays by same index?
- How to sort a list / array of string version number?
- Is there a sorted collection type in .NET?
- BindingList.Sort() to behave like a List.Sort()
- How to enable DataGridView sorting when user clicks on the column header?
- how to sort a collection by datetime in c#
- Use LINQ to move item to top of list