Search code examples
c#.netoopdynamicoverloading

Method overloading with dynamic data types


Why compiler is restraining to overload method in below way, Compilation Error i get in update method with dynamic type parameter.

Error - Type 'Program' already defines a member called 'update' with the same parameter types

static void update(string name)
    {

    }
static void update(object name)
    {

    }

static void update(dynamic name)
    {

    }

Solution

  • Because dynamic is also a type of object. You can check the generated IL code. So its giving compilation error for

    static void update(object name)
        {
    
        }
    
    static void update(dynamic name)
        {
    
        }