Getting the ambiguous call as arrangement of parameters are different: short,int / int,short /byte,int / int,byte
As Function signature is:
1.Number of arguments/parameters
2.Type of arguments/parameters
3.Arrangement of arguments/parameters
Why the call is ambiguous ? should it belongs to the similar type ?...
code:
class Program
{
static void Main(string[] args)
{
test abbb = new test();
//abbb.add(2.2f,1);
// abbb.add(2,2.2f);
abbb.add(255,1);
abbb.add(1,256);
Console.ReadLine();
}
}
class test
{
public int add(byte i , int f) {
return i + f;
}
public int add(int i, byte f)
{
return i + f;
}
public int add(short i, int f)
{
return i + f;
}
public int add(int i, short f)
{
return i + f;
}
}
By default, any 'Magic Number' will be treated as an Integer, but sometimes for ease of use the compiler can convert to another number format implicitly if it has enough information to do so. In order to get around the ambiguous calls, you would be best explicitly defining typed variables for the numbers first, then passing them into the functions to remove any ambiguity.