How many classes are allowable in one file?

  • Thread starter Thread starter light_wt
  • Start date Start date
L

light_wt

Hi,

Happy NY, folks. I've just a two simple questions:

Can there be more than 1 class per file?

Can I declare more than 1 public class per file?

I tend to think yes on both. Is there execptions?

Thanks.

light_wt.
 
light_wt,

Yes, you can have more than one class per file. I don't believe there
is a limit (although it may become impractical at some point if you have too
much).

One caveat. The win forms designer likes to have one class (the form it
is designing) per file. It has something to do with the resx files it
generates.

Hope this helps.
 
It is only a convention that people put one class per file but you can have
as many as you want. You could have your entire application contained
within a single file if you want.
 
light_wt said:
Can there be more than 1 class per file?
Can I declare more than 1 public class per file?
I tend to think yes on both. Is there execptions?

You can have more than one class in a file.

I think the Windows Forms Designer will only let you view and edit a form if
it is the first class in the file.

P.
 
Back
Top