List. Add, Remove.

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

shapper

Hello,

I have a list of an enumeration: IList<Role> Roles and a variable Role
myRole.

Consider myRole value is Role.A. I need to:
- Add Role.A to IList<Role> only if IList<Role> does not contain
Role.A.
- If I add Role.A to Roles then I need to remove Role.C and Role.F
from list Roles if they exist.

How can I do this?

Thanks,
Miguel
 
shapper said:
Hello,

I have a list of an enumeration: IList<Role> Roles and a variable Role
myRole.

Consider myRole value is Role.A. I need to:
- Add Role.A to IList<Role> only if IList<Role> does not contain
Role.A.

Wouldn't that be using the IList.Contains(Role.A) ?
- If I add Role.A to Roles then I need to remove Role.C and Role.F
from list Roles if they exist.

How can I do this?

It would be if contains, then find indexof and the removeat.


http://www.dotgnu.org/pnetlib-doc/System/Collections/IList.html
http://www.codegod.de/WebAppCodeGod/Namespace-System.Collections.Generic-Class-List.aspx
 
Back
Top