Partial class in different namespaces

前端 未结 6 636
再見小時候
再見小時候 2020-11-30 09:50

Can I create partial class in different namespaces? Will it work correct? e.x.:

class1.cs

namespace name1
{
    public partial class Foo
    {
               


        
6条回答
  •  Happy的楠姐
    2020-11-30 10:07

    Here are some point to consider while implementing the partial classes:-

    • Use partial keyword in each part of partial class.

    • Name of each part of partial class should be the same but source file name for each part of partial class can be different.

    • All parts of a partial class should be in the same namespace.

    • Each part of a partial class should be in the same assembly or DLL, in other words you can't create a partial class in source files of a different class library project.

    • Each part of a partial class has the same accessibility. (like private, public or protected)

    • If you inherit a class or interface on a partial class then it is inherited on all parts of a partial class.

    • If a part of a partial class is sealed then the entire class will be sealed.

    • If a part of partial class is abstract then the entire class will be considered an abstract class.

提交回复
热议问题