Resolving Overloaded Members

C# employs a deliberate mechanism to determine which overloaded class member is called in a program. Understanding these rules assists in building overloaded class members that are robust enough to meet requirements. Here are a few guidelines to help determine which overloaded method, indexer, or operator is executed. They are also the sequence of steps the compiler uses to resolve overloaded members.

1.
Clearly, if there is an exact match, then that member is selected.
2.
The candidate list of members is evaluated for a best match. Identifying the best match involves a couple of steps. Basically, one member is better than another if there is an implicit conversion of parameters to that member and not to the others. ...

Get C# Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.