score:1
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.
Source: stackoverflow.com
Related Articles
- How to find key value pair in a dictionary with values > 0 with key matching a certain string pattern?
- The given value of type String from the data source cannot be converted to type int of the specified target column
- C# .net 3.5+ Dictionary<string, string> key/value pair displaying value as default choice – MVC select list
- how do i convert Dictionary string string to array of key value pair of string and string using linq and c#
- How to find string in Dictionary list and get its pair integer value
- List or Array of String Contain specific word in Html Source Code
- I am having difficulty displaying a string from a value from my ViewModel using Razor
- Value cannot be null. Parameter name: source
- How do I sort strings alphabetically while accounting for value when a string is numeric?
- C# - code to order by a property using the property name as a string
- LINQ syntax where string value is not null or empty
- How to resolve Value cannot be null. Parameter name: source in linq?
- Linq filter List<string> where it contains a string value from another List<string>
- How to assign empty string if the value is null in linq query?
- How to Convert the value in DataTable into a string array in c#
- Check if a String value contains any number by using Lambda Expression
- LINQ to Entities - How to return a single string value from entity
- Linq: Checking if string column has a value (ie. is not null or empty)
- .NET String parsing performance improvement - Possible Code Smell
- LINQ Source Code Available
- Efficient way to unindent lines of code stored in a string
- Trim String value with particular pattern in C#.NET
- .NET 4 Code Contracts: "requires unproven: source != null"
- Intersect two lists and return the similarity with the preserved order of the original first string value
- Add " | " in string if where string value is not null or empty
- Split string and set default value if separator not found WITH LINQ
- SQL Trigger is trying to insert a null value but my C# code is passing int 300?
- LINQ for string StartsWith some value in List<string>
- How to Deal With Dapper return Key Value pair with Dynamic from LINQ
- Split comma separated string and compare each value in a List
- How to get new record in SQL Server or C# by checking if id exists
- The specified type member 'UserName' is not supported in LINQ to Entities
- Linq to SQL for WebMatrix (Web Pages)
- Find value in Dictionary<int,List<int>>
- Simplify the following algorithm
- Flatten LINQ subselect so 1..n becomes one row
- GroupBy Issue in LINQ
- LINQ syntax and the where clause
- Entity Framework List Contains in lambda
- Taking last items from each category with Linq extension
- Entity Framework object limitations in aggregate LINQ query
- Dynamic LINQ - Groupby with ExpandoObject Results in Error: No Applicable Indexer
- How to check if all strings in a string array are all digits?
- LINQ to SQL separation and reusability of data structures
- What is the "=>" sign in LINQ queries?
- How I can filter a dataTable with Linq to datatable?
- Multiply filtering in MongoDB
- How do I write a LINQ query to combine multiple rows into one row?
- LINQ Sum of entries based on latest date
- Linq Select Statements - Where Not In