| | |
Understanding Partial Classes...
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
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
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
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!
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.
![]() |
Other Threads in the C# Forum
- Previous Thread: Preventing out of memory errors while threading
- Next Thread: How to read a ini file from c#
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox concurrency control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ globalization httpwebrequest image index input install java label list listbox listener mandelbrot math microsoftc#visualexpress mouseclick mysql networking operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





