C# dictionary: check for key in case insensitive manner
I want to check if a dictionary given to me contains a particular string
as a key. I need to make this check in a case insensitive manner. For
example if someone passes me a HTTP request object which has a dictionary
of strings called headers. I need to be able to check if "Content-Type" or
"content-type" or "content-Type" is a key in the request.headers
dictionary.
The usual ContainsKey() does not work since I think it checks for the key
in a case sensitive manner.
I also know that there exist ways to work on this by defining the
dictionary to be case insensitive. But here I do not have control over
what kind of dictionary is passed to me.
No comments:
Post a Comment