Skip to content

pangram: fix all-contains-case-insensitive sample code #2184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# `All` with `Contains` using case-insensitive comparison

```csharp
using System;
using System.Linq;

public static class Pangram
{
private static readonly StringComparison xcase = StringComparison.CurrentCultureIgnoreCase;

public static bool IsPangram(string input)
{
return "abcdefghijklmnopqrstuvwxyz".All(c => input.Contains(c, xcase));
Expand All @@ -16,9 +17,9 @@ public static class Pangram

- This begins by setting a variable for a case-insensitive `string` comparison.
- It then checks if all letters in the alphabet are contained in the input,
using the [LINQ][linq] method [`All`][all] with the `String` method [`Contains`][contains].
using the [LINQ][linq] method [`All`][all] with the `String` method [`Contains`][contains].
- `Contains` takes the optional [`StringComparison`][stringcomparison] argument,
but a case-insensitive comparison is about seven times slower than if the input were lowercased and then an exact comparison were done.
but a case-insensitive comparison is about seven times slower than if the input were lowercased and then an exact comparison were done.

## Shortening

Expand Down