Search code examples
c#classmethodspartial

Partial class sharing same method names


If a partial class has the same method name but different types I will get an error right?

public partial class Employee
{
    public int sum()
    {
    }
}

public partial class Employee
{
    public string sum()
    {
    }
}

Solution

  • Yes, it does:

    'Employee' already defines a member called 'sum' with the same parameter types

    Partial classes are just the same as regular class, except their definition is split in two sources. They have to comply to every rule regular classes have. That includes rules concerning the uniqueness of method signatures.