CSharp - What is the output: proper method overloading

Question

Is the following code segment an example of method overloading.

class MyClass
{
      public int Add(int x, int y)
      {
          return x + y;
      }
      public double Add(int x, int y, int z)
      {
          return x + y+ z;
      }
}


Click to view the answer

Yes.

Is the following code segment an example of method overloading?

class MyClass
{
     public int Add(int x, int y)
     {
         return x + y;
     }
     public double Add(int x, int y)
     {
         return x + y;
     }
}


Click to view the answer

No.

Note

The compiler will not use "return type" to differentiate the methods.

Return type is not considered a part of a method signature.

Related Quiz