score:1

Accepted answer

The thing that sticks out to me with what you have in the code is the

x.Key.Contains("true")

part. This does a string comparison with case sensitivity. Your value for the dictionary item converts the boolean to a string with either the value "False" or "True". The simplest solution would be to change your linq where statement to:

x.Key.Contains("True")

but this may not be the best solution, as this looks for "True" in any part of the string, and is still case sensitive. A "better" solution would be to use a comparison method that allows for case insensitivity. An extension method I have used a few times in projects is this:

public static bool Contains(this string source, string toCheck, StringComparison comp)
{
    if (string.IsNullOrEmpty(toCheck) || string.IsNullOrEmpty(source))
        return false;
     return source.IndexOf(toCheck, comp) >= 0;
}

and you could change the where statement to:

x.Key.Contains("True", StringComparison.InvariantCultureIgnoreCase)

If you are not using .NET 3.0 or greater, you can easily just change that to a static utility method.


Related Articles