I've read up to the point where the author explains partial classes.

I understand the general concept - they're used when a class is so big that it is better to split it across files.

I created two .cs files. Let's say one is CS1.cs and the other is CS2.cs

For each file I have a partial class MyPartialClass

I have tried implementing a Constructor in one file and a method in the other, in which the Constructor calls the method across files, however I receive error messages saying that the method doesn't exist in this context or the Constructor (with parameters) isn't realized.

When I qualify a partial class with its respective namespace it is treated as that namespace's specific class.

I've tried the using directive (where one file is using the other file and vice versa) so that the partial class would possibly be realized, but to no effect.

I've even tried NOT doing any of this, implementing the "using" calls for each namespace in the separate files and simply calling the constructor of one but with disappointing results (still treated as a separate class and not a partial class).

Basically, how do I make a partial class realized? In other words, how do I invoke commands from a part of the class within a file that has the same partial class, or is this impossible?

I know there is something I am not understanding. Hopefully someone can steer me in the proper direction!


8 Years
Discussion Span
Last Post by Alex Edwards

I reattempted this problem without using namespaces, and the partial class realized each others methods...

I guess this is solved, but I'd still like to know why I must leave off the namespaces for the class to realize methods in a different file with the same partial class declaration/definition?

Edit: Figured it out. If you use the same namespace for each partial class then it's considered the same partial class. I guess this makes sense.


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.