Overload Resolution

When multiple overloads for a method with a given name exist, one of the compiler’s duties is to figure out which method is to be called given a certain argument list. A whole set of rules exists to figure out the “best target.” Those rules largely correspond to common sense and what developers would expect to be the best match. A simple example can be given using the Math.Abs method, which has seven overloads:

public static decimal Abs(decimal value);public static double Abs(double value);public static float Abs(float value);public static int Abs(int value);public static long Abs(long value);public static sbyte Abs(sbyte value);public static short Abs(short value);

Most, if not all, readers will ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.