Dictionary

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have the following Dictionary:

var roles = new Dictionary<Role, string>();
roles.Add(Role.Administrator, "Administrador");
roles.Add(Role.Collaborator, "Colaborador");

I have a variable role of type Role (enum).

I want remove all items from my Dictionary with exception of the one
which key is the same as in role variable.

How can I do this?

Thanks,
Miguel
 
I would think the quickest way would be to clear out the dictionary and just
add the one you want to keep back into it.
 
I would think the quickest way would be to clear out the dictionary and just
add the one you want to keep back into it.

Forget it ... I was trying to use Linq but no method was available ...

I forgot to add using System.Linq and forgot that when I don't add it
I don't get the options as I right!

Thanks,
Miguel
 
Hello,

I have the following Dictionary:

var roles = new Dictionary<Role, string>();
roles.Add(Role.Administrator, "Administrador");
roles.Add(Role.Collaborator, "Colaborador");

I have a variable role of type Role (enum).

I want remove all items from my Dictionary with exception of the one
which key is the same as in role variable.

How can I do this?

Thanks,
Miguel

Hi,

You could create a list of all the keys in the dictionary and then
delete them, comparing each with your value, if you find your value
you do not remove t
 
Back
Top