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

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -