I have the following partial method:
public partial class Foo
{
public virtual partial void PartialMethodFoo();
public virtual partial void PartialMethodFoo()
{
System.Console.WriteLine("Message One.");
}
}
The above partial method can be overriden with two approaches.
Approach #1
public partial class Bar : Foo
{
public override partial void PartialMethodFoo();
public override partial void PartialMethodFoo()
{
base.PartialMethodFoo();
System.Console.WriteLine("\nMessage Two.");
}
}
Approach #2
public class Bar : Foo
{
public override void PartialMethodFoo()
{
base.PartialMethodFoo();
System.Console.WriteLine("\nMessage Two.");
}
}
Both approaches result in overriding the partial method that was marked as virtual
. But what is the difference between both approaches of overriding a partial method?
CodePudding user response:
There is no functional difference. All a partial method does is defines a method that can optionally be implemented somewhere else. There's no point in defining a partial method in Bar
(or Foo
for that matter) if you're going to implement the method somewhere else anyway.