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 Query
- How to find key value pair in a dictionary with values > 0 with key matching a certain string pattern?
- how do i convert Dictionary string string to array of key value pair of string and string using linq and c#
- The given value of type String from the data source cannot be converted to type int of the specified target column
- How to Deal With Dapper return Key Value pair with Dynamic from LINQ
- C# .net 3.5+ Dictionary<string, string> key/value pair displaying value as default choice – MVC select list
- Group to key-value pair where value is a list of elements that share the same key
- Regex or Linq to capture the key and value pair in c#
- How to get value from matching key from keyvalue pair list in vb.net using linq?
- check if string contains dictionary Key -> remove key and add value
- Merging a key value pair List while removing duplicates C#
- update value of Key in key value pair
- Extract key value from a string Using Linq
- How to get a key value pair out of an array of objects
- How to Lazy Load child object with string primary key in Entity Framework Code First?
- JSON - LINQ Query for object or an array to group two data with same key value pair
- How to find string in Dictionary list and get its pair integer value
- linq to sql c#: replace a foreign key with its string value and keep the table structure
- Using LINQ to read key value pair from configuration file
- Storing result of linq in keyvaluepair with key and value after spliting the String using comma seperator
- List or Array of String Contain specific word in Html Source Code
- Linq Query: Convert Key value pair to generic list of objects
- I am having difficulty displaying a string from a value from my ViewModel using Razor
- How to get nested key value pair from dictionary with linq
- How to get key value pair from appSettings into a collection of SelectListItem?
- Using Group Join return Key Value Pair
- Obout Grid foreign key value Object Data Source
- Remove all elements from a Key value pair which are equal to elements in a list?
- 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
More Query from same tag
- DISTINCT() and ORDERBY issue
- LINQ group by on a single column
- How do you specify the order of columns of a doddlereport without creating a new object
- Get count and avg for specific criterias and also the rest
- How to bind LINQ data to dropdownlist
- linq over strings C#
- LINQ to SQL omit field from results while still including it in the where clause
- LINQ: left join instead of inner join
- Please explain System.Linq.Enumerable.Where(Func<T, int, bool> predicate)
- Combine results after join and groupby with DataTable and List<Object>
- Why am I getting this Linq to Nhibernate exception when I add the same expression to the query twice?
- Linq Complex Query Search between Dates
- Adding varying values to a list inside of a Concurrent Dictionary
- Getting Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. .exception
- async LINQ query
- LINQ C# - Combining multiple groups
- Random Linq Query
- Exclude a column from a select using LINQ
- Any better way for converting array to concurrent dictionary using linq or IEnumerable?
- Linq 'contains' query taking too long
- Can an object be instantiated only once inside a linq query?
- Create Generic method that returns sort lambda expression
- Comparing parsed XML with a string
- How to sort a list of strings with a specific format using string.split?
- LINQ: Cannot insert duplicate key row in object 'dbo.tblOutstandingCompletions' with unique index
- How to group and join to get counts?
- Reversing IQueryable based on passed property for sorting logic
- xml XDocument from isolatedstorage, for use with LINQ
- How could I LINQ's GroupBy() with a boundary?
- XElement - reading the nodes C#