Understanding Partial Classes...

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Understanding Partial Classes...

 
0
  #1
Aug 17th, 2008
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!

-Alex
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: Understanding Partial Classes...

 
0
  #2
Aug 17th, 2008
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.

Thanks!
Last edited by Alex Edwards; Aug 17th, 2008 at 1:51 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC