• 14
• 12
• 9
• 10
• 13

# [.net] Quickie Collection question

This topic is 3297 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Data structures are not my strong suit. I am looking for a collection that will do this general pattern better than List<T>:
if( Collection.Contains( foo ) ){
return;
}

// process foo.
// recurse.


foo is some arbitrary reference type. Normally I'd go for some list wrapper over a balanced tree, but .NET sorted stuff seems to require pairs and seems not to want to just use the references (or some internal token) as the balance condition. Something in the standard lib I'm missing? Some well known non-standard lib I'm missing? Advise, questions?

##### Share on other sites
I don't have an answer but let me check I understand the question ... you want something which will permit one and only one instance of a particular object (I think this is a 'set' in mathematical terms).

##### Share on other sites
That looks like exactly the right thing but it is only in 3.5, which implies there is no Framework class for the job in 2.0.

Using a Hashtable<T,object> and setting the value to something (anything :p) would also do the trick but it will clearly be a bit inefficient.

##### Share on other sites
Yes, a set would be acceptable, though I don't necessarily need the behavior of a set. And I am constrained to 2.0 for now, but that looks good. [edit: though this 2.0 compatible lib provides a simple hashset and seems to work well]

Thank you gentlemen.

[Edited by - Telastyn on March 13, 2009 1:49:55 PM]