Question: I am looking for an elegant way, preferably a short linq expression, to count how many alphanumeric chars a given string contains.

The 'boring' way I do it now is this:

```
int num = 0;
for (int i = 0; i < password.Length; i++)
{
    if (!char.IsLetterOrDigit(password, i))
    {
        num++;
    }
}
if (num < MinRequiredNonAlphanumericCharacters)
    return false;

```

This is rather short already, but I am sure with some linq magic this can be done in an even shorter, equally understandable expression, right?

Answer: 
```
int num = password.Where((t, i) => !char.IsLetterOrDigit(password, i)).Count();

if (num < MinRequiredNonAlphanumericCharacters)
    return false;

```
You can use `Take()` to ensure that you don't inspect more letters than necessary:

```
int minCount = password.Where(x => !char.IsLetterOrDigit(x)).Take(MinRequired).Count();
if (minCount < MinRequired) { // No good }

```

The idea is that we only keep checking until you've hit the minimum number. At that point, we can stop, because we know we have an admissible password. `Take()` takes as many as it can, and no more, so if there aren't enough, it will just return a number less than you've requested.