Extract Dictionary / datatable value using linq

Hi,
I want to write linq query in vb.net
to extract specific value from dictionary or datatable.
Tried writing this query
in_DictTitleCode.Where(Function(a) a.key "Miss ").Select(Function(a) a.value).ToString

output of this is
“System.Linq.Enumerable+WhereSelectEnumerableIterator2[System.Collections.Generic.KeyValuePair2[System.String,System.String],System.String]”

Hi,

You need to do something like this,

in_DictTitleCode.OrderBy(Function(kvp) kvp.Key)
        .SkipWhile(Function(kvp) kvp.Key <= startSite)
        .Where(Function(kvp) kvp.Key <> mainSite AndAlso kvp.Key <> returnSite)
        .Select(Function(kvp) kvp.Value).FirstOrDefault()
1 Like

Why should i do order by and skip while ?
only where and select function is nt enough?
also for string comparison can i use kvp.key.equals(“Miss”)
i tried this way but still it didn’t work

@Krutika_Kotkar
A LINQ for a dictionary will have a different Syntax as a LINQ for a Datatable.

It seems to me that you are trying to get value of dict item with the Key “Miss”
similar to DictionaryVar(“Miss”)

If you are interessted into what different, please share some sample entries and expected result with us. So we can help you

Hi ,
in_DictTitleCode.Where(Function(kvp) kvp.Key.equals(“Miss”)).Select(Function(kvp) kvp.Value).FirstOrDefault()
this worked for dictionary

any idea how to modify if it’s a datatable ?

DT.select(“Key Like’%Miss%’”).FirstOrDefault())(“Location”).ToString

Try like this…