How to check if dictionary contain String

I have a dictionary whit key (email address) and value (number email send)

I need to check if email already exists in the dictionary

can Somebody help me?

5 Likes

Hello!

Try to use: dictionary.Contains(String).

It will return a True/False value.

Regards,

2 Likes

"impossible cinvert the value “UiPathCore.GenericValue” in “System.Collection.GenericsKeyValuePair(of String, integer)”

Why?

yourDictionary.Keys.Contains(yourString)

9 Likes

@dnllorenzetti there is also a Microsoft.Activities.Extension package available for UiPath that has some useful activities for the Dictionary data type. If you had that installed you could use the Key exists in dictionary activity.

2 Likes

Or just use “Values exists in dictionary” and “Keys exists in dictionary” Activities :smiley:

While they’re useful (especially AddToDictionary, since it’s void), for Exists it’s IMHO more efficient to use the method call.
Compare the 2:
bool keyExists = KeyExistsInDictionary(dictionary, value) if (keyExists) {...}

or

if (dictionary.Keys.Contains(value) {...}

It saves you space on the designer and an extra variable. While it doesn’t sound like much, in more complicated workflows it adds up. It’s still personal/team preference though.

1 Like

I need to build something that for each key (email) counts how many times a message has been sent.

What do you recommend?