Collection Class contains

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all.

I have a collection class that holds a number of clauses. One particular
type of clause has a member variable called type - this is an enum.

How do I check this collection class to see if it has a clause of a
particular type?

I know I'll have to implement a contains (or similar) method, but I'm after
code examples.

Thanks in advance.

Jon
 
"Jon" <[email protected]> a écrit dans le message de (e-mail address removed)...

| I have a collection class that holds a number of clauses. One particular
| type of clause has a member variable called type - this is an enum.
|
| How do I check this collection class to see if it has a clause of a
| particular type?
|
| I know I'll have to implement a contains (or similar) method, but I'm
after
| code examples.

If you are using .NET 2.0 generic collections :

bool NameMatch(MyType value)
{
return value.Name == "Joanna";
}

void Test()
{
List<MyType> items = new List<MyType>();

// add items to list

MyType found = items.Find(NameMatch);

...
}

Joanna
 
Here I have an object called "Order"
It has an (int) property called "OrderID"

I passed in an orderId to try and find a match.


public Order Contains( int orderId )
{

foreach( Order item in base.InnerList )
if( item.OrderID .Equals(orderId) )
{
return item;
}
return null;

}
 

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

Back
Top