I am having a hard time understanding the usage of partial methods.
Can you provide an example that doesn't have to do with LINQ or that sort of database things?
Are partial methods the same things like when we are in the WinForms and coding behind it, if we use a method, it gets compiled, but if we don't, then it gets removed by the compiler? Is that correct?
When you have a partial class, you can define the signature of a method in one file and have the implementation in another. That's a partial method.
So in one file you have:
And in another you have
This lets the first file call
Barwithout worrying about whether or notBaris implemented. IfBaris not implemented somewhere, then calls to it are removed (from here):A partial method must return void, else it'd be unsafe to remove all method calls should the method not be implemented:
As with partial classes, the main use is working with generated code:
So you might have generated code that makes a call to a partial method (defined without implementation in the generated code) and you are free to extend that partial class and implement that partial method if you want / need to.