What are the benefits to using a partial class as opposed to an abstract one?

后端 未结 8 1632
花落未央
花落未央 2021-01-18 01:19

I have been reading Programming Microsoft® Visual C#® 2008: The Language to get a better understanding of C# and what can be done with it. I came across partial classes whic

相关标签:
8条回答
  • 2021-01-18 02:00

    A good usage example is when one side of the partial class is generated (such as an ORM)

    0 讨论(0)
  • 2021-01-18 02:01

    The great thing about a partial class is that you can take an existing class and add on to it. Now this sounds a lot like inheritance, but there are a lot of things that inheritance can't do that partial classes will.

    Here's one think about the Linq to SQL classes generated for you. They are autogenerated meaning you shouldn't modify them. Without a partial class, you can't attach an interface. You could create a new class and derive that from the Linq to sql class, but that really doesn't get you anything because you can't upcast the linq to sql class to your class with the interface.

    0 讨论(0)
提交回复
热议问题