List. Add, Remove.

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
 
M

Mr. Arnold

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Intersection of Lists 5
Generics 7
Add item at start 5
List<String> 15
Linq query 3
List. Check items 3
Sring[] to List<MyEnumeration> 5
Dictionary 3

Top