Home > Enterprise >  Compile time error CS0759 being generated in relevance to a partial method?
Compile time error CS0759 being generated in relevance to a partial method?

Time:11-05

Why is compile time error CS0759 generated?

No defining declaration found for implementing declaration of partial method 'method'.

public partial class Foo
{
    public extern partial void SamplePartialMethod(); // CS0759
}

Clearly I did define the defining declaration of the partial method rather than the implementation declaration. Yet compile time error CS0759 is generated?

It does not make sense.

CodePudding user response:

The extern modifier is used to declare a method that is implemented externally.

source

So by including the extern keyword, you're effectively providing the implementation for the partial method, not the definition.

This code doesn't cause that error because it declares the implementation separately from the declaration:

public partial class Foo
{
    public extern partial void SamplePartialMethod();
    public partial void SamplePartialMethod();
}
  •  Tags:  
  • c#
  • Related