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

  • Thread starter Thread starter Maxwell2006
  • Start date Start date
M

Maxwell2006

Hi,



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



Thank you,

Alan
 
Maxwell2006 said:
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
 
Maxwell2006 said:
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?
 
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
 
A.M-SG said:
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.
 
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.
 
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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top