To check if a dictionary contains a value in C#, you can use the ContainsValue()
method. This method returns true if the value is found in the dictionary, otherwise it returns false.
Here's an example:
main.cs410 chars18 lines
In this example, we create a dictionary of type string
and int
and add some key-value pairs to it. We then use the ContainsValue()
method to check if the dictionary contains the value 2. If it does, we print a message to the console. If not, we print a different message.
gistlibby LogSnag