c# - How to do "like" on dictionary key? -
c# - How to do "like" on dictionary key? -
how can "like" find dictionary key? i'm doing:
mydict.containskey(keyname);
but keynames have additional word appended (separated space), i'd "like" or .startswith(). comparisons this:
"key1" == "key1" //match "key1" == "key1 someword" //partial match
i need match in both cases.
you can utilize linq this.
here 2 examples:
bool anystartswith = mydict.keys.any(k => k.startswith("key1"))
bool anycontains = mydict.keys.any(k => k.contains("key1"))
it worth pointing out method have worse performance .containskey method, depending on needs, performance nail not noticable.
c# .net linq
Comments
Post a Comment