© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
palapapa

❔ Why doesn't every method in Collection<T> has an extension point?

For example,
Insert
Insert
calls
InsertItem
InsertItem
, and
InsertItem
InsertItem
by default calls
items.Insert(index, item);
items.Insert(index, item);
(source), where
items
items
is the
IList<T>
IList<T>
instance passed into its constructor.
InsertItem
InsertItem
is also virtual. This means that to customize
Collection<T>.Insert
Collection<T>.Insert
, you can either override
InsertItem
InsertItem
, or pass an
IList<T>
IList<T>
instance into the constructor of
Collection<T>
Collection<T>
that has the custom behavior you want.
But for methods like
Contains
Contains
, there isn't an extension point like, for example,
ContainsItem
ContainsItem
. That means the only way to customize
Contains
Contains
is to pass an
IList<T>
IList<T>
instance into the constructor of
Collection<T>
Collection<T>
that has the custom behavior you want.
This raises the question of why there are two ways to customize methods like
Insert
Insert
,
Clear
Clear
,
Remove
Remove
, and the setter of the indexer(
SetItem
SetItem
), while there is only one for the other methods, like the getter of the indexer and
Contains
Contains
. Is there any specific reason for this?
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

✅ Why return IServiceCollection in an extension method?
C#CC# / help
3y ago
❔ Why is PointF not simply Point<float>?
C#CC# / help
3y ago
Find doesn't return my collection
C#CC# / help
2y ago
interface vs extension method vs method in class
C#CC# / help
3y ago