Can I create partial class in different namespaces? Will it work correct? e.x.:
class1.cs
namespace name1 { public partial class Foo { Bar1(){ return 10; } } }
class2.cs
namespace name1.name2 { public partial class Foo { Bar2(){ return 100; } } }
main.cs
using name1; using name1.name2; namespace mainClass { public class mainClass { Foo classFoo = new Foo(); int Count = classFoo.Bar1() + classFoo.Bar2(); // Will Count = 110? } }
What should I do to make it work? (if my example not correct)
So the short answer to your question is: No.
It's still partial but it allows you to share it between both projects, keep them synchronized and at the same time have version/framework specific code in the partial classes. Show activity on this post. I've had similar issues with this. I kept my partial classes in my Data project so in your case the 'MyProject.
A partial class is a special feature of C#. It provides a special ability to implement the functionality of a single class into multiple files and all these files are combined into a single class file when the application is compiled. A partial class is created by using a partial keyword.
Inheritance cannot be applied to partial classes.
A class's name includes it's namespace, so name1.Foo
and name1.name2.Foo
are two completely separate types. So the short answer to your question is: No.
Why do you need to do something like this?
Partial class is only possible in same namespace and same assembly.
Namespace could be in two different assemblies but partial class could not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With