© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
4 replies
Vir Godem

How do collections implement Remove and Contains?

In particular, in the case of records. Do they look for exact references, or do they apply the record equality test as I'd expect them to?

Let's say I've got a simple record like:
record S(int X, string Y);
record S(int X, string Y);


And I've got a collection of
S
S
, such as a
HashSet
HashSet
. Will the HashSet test the values of
X
X
and
Y
Y
and return true if it finds that the HashSet contains such an element? Or will it need the exact reference to
S
S
?

That is, would the following be enough to find a reference containing an
S
S
instance with
X = 5
X = 5
and
Y = "42"
Y = "42"
?
return HashSet.Contains(new S(5, "42"));
return HashSet.Contains(new S(5, "42"));
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How do I implement this?
C#CC# / help
2y ago
✅ How do I deal with generic covariance and collections types?
C#CC# / help
3y ago
ISerializationSurrogate and collections issue
C#CC# / help
7mo ago
How do I implement mesh projection?
C#CC# / help
2y ago