Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention for partial classes file names? [duplicate]

If I have partial classes in C#, what should the file names be?

The class is called partial class Logic and would exist out of two or maybe three separate files.

like image 579
Simon Verbeke Avatar asked Dec 30 '11 12:12

Simon Verbeke


People also ask

Can partial class have different names in different files?

The source file name for each part of the partial class can be different, but each partial class's name must be the same. The name of all parts of a partial class should be the same. All parts of a partial class should be in the same assembly.

Can two classes have same partial name?

In your case it will raise an error mentioning you already have defined a method with the same name. One modern caveat - that code would be totally fine if the partial classes were split into 2 separate files meant for 2 separate platform targets in a multi-targeted .

What is the best choice for a naming convention for a file?

Capitals, Underscores, and Dashes Using these is the best way to make file names easy to read when you're quickly scanning for the image you want. Some software doesn't recognize spaces in file names and therefore won't open your file.

Do partial classes have to be in same namespace?

All parts of a partial class should be in the same namespace. Each part of a partial class should be in the same assembly or DLL, in other words you can't create a partial class in source files of a different class library project. Each part of a partial class has the same accessibility.


1 Answers

For a class called Logic, I'd probably go for Logic.something.cs (where "something" is different for each file). This would be in the same style as the partial classes that Visual Studio generates (eg. the .designer.cs files for forms)

like image 116
Daniel Lo Nigro Avatar answered Nov 15 '22 15:11

Daniel Lo Nigro