Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tompazourek committed May 30, 2020
1 parent 1b7e26c commit 75abd4a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ PM> Install-Package NaturalSort.Extension
Usage
-----

The `NaturalSortComparer` is a `IComparer<string>`, which you can use in all the places that accept `IComparer<string>` (e.g. `OrderBy`, `Array.Sort`, ...)

You can create the comparer directly, but you need to specify the inner string comparison mechanism (whether it's ordinal, which culture it uses, whether it's case sensitive, ...)

The recommended method for best results is to create the comparer by using the `StringComparison` enum.

```csharp
Expand All @@ -42,10 +38,12 @@ var ordered = sequence.OrderBy(x => x, StringComparison.OrdinalIgnoreCase.WithNa

For more information about natural sort order, see: [Sorting for Humans: Natural Sort Order (Coding Horror)](https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/).

The `NaturalSortComparer` created using the extension method is a `IComparer<string>`, which you can use in all the places that accept `IComparer<string>` (e.g. `OrderBy`, `Array.Sort`, ...)

If you wish, you can be more explicit by not using the `.WithNaturalSort()` extension method, and using the constructor directly:

```csharp
new NaturalSortComparer(StringComparison.OrdinalIgnoreCase)
```

If you are using a custom `IComparer<string>` (or `StringComparer`), you can also use that instead of the `StringComparison` enum. However, `StringComparison` should perform better as it avoids constructing substrings.
Note that if you are using a custom `IComparer<string>` (or `StringComparer`), you can also use that instead of the `StringComparison` enum. **However, if you use `StringComparison`, it should perform better as it avoids constructing substrings.**

0 comments on commit 75abd4a

Please sign in to comment.