471,317 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

C#2: Can we have a partial class consists of 3 source files?

Hi,

Typically partial classes consist of two .cs files. Can I have them in 3
source file?

Thank you,

Alan
Feb 3 '06 #1
7 1360
SP

"Maxwell2006" <al******@newsgroup.nospam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

Typically partial classes consist of two .cs files. Can I have them in 3
source file?


Yes it is. From the VS help under partial classes:

"It is possible to split the definition of a class or a struct, or an
interface over two or more source files"

SP
Feb 3 '06 #2
Yes it is possible.
"Maxwell2006" <al******@newsgroup.nospam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

Typically partial classes consist of two .cs files. Can I have them in 3
source file?

Thank you,

Alan

Feb 3 '06 #3
Maxwell2006 <al******@newsgroup.nospam> wrote:
Typically partial classes consist of two .cs files. Can I have them in 3
source file?


Yes. Whether it's a good idea or not is a different matter. Where
there's no good reason to split classes, it's worth keeping the whole
code in one file. Partial classes are most useful when some of the code
is autogenerated and some is hand-written. This doesn't *usually* end
up extending to three parts.

If you just want to split a class up into three files because it's very
big, you might want to consider making more classes instead. I'm not
saying that *is* your situation, of course - I just thought I'd mention
it in case?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 3 '06 #4
Hi Jon,

Thank you for help.

Does IDE fully supports classes broken down into five files?
Can I break down my WinForm form classes into more than two files and still
have designer support?

Thanks again,
Alan

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Maxwell2006 <al******@newsgroup.nospam> wrote:
Typically partial classes consist of two .cs files. Can I have them in 3
source file?


Yes. Whether it's a good idea or not is a different matter. Where
there's no good reason to split classes, it's worth keeping the whole
code in one file. Partial classes are most useful when some of the code
is autogenerated and some is hand-written. This doesn't *usually* end
up extending to three parts.

If you just want to split a class up into three files because it's very
big, you might want to consider making more classes instead. I'm not
saying that *is* your situation, of course - I just thought I'd mention
it in case?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Feb 3 '06 #5
A.M-SG <al******@newsgroup.nospam> wrote:
Does IDE fully supports classes broken down into five files?
Can I break down my WinForm form classes into more than two files and still
have designer support?


I don't know - have you tried?

As I say though, I wouldn't recommend it personally.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 3 '06 #6
I just created a form and tried to add 3rd cs file to it.

Compiler perfectly recognizes; however, IDE cannot underestand it. That
meanns IDE adds resouces and adds separated InitComponent.

In essence, you cannot add 3rd partial class to forms because it confuses
IDE.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
A.M-SG <al******@newsgroup.nospam> wrote:
Does IDE fully supports classes broken down into five files?
Can I break down my WinForm form classes into more than two files and
still
have designer support?


I don't know - have you tried?

As I say though, I wouldn't recommend it personally.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Feb 4 '06 #7
Hi Alan,

The compiler does support partial classes in multiple files. However, the
designer only supports 1 .cs file for the designer generated code, and 1
for your own code.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 6 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.