C# – What naming convention for C# file that contains multiple classes

cnet

In C# projects, we frequently group small and tightly related classes into the same .cs file. This practice reduces the friction of dealing with a myriad of files containing close to no actual code. Yet, is there an established practice to name the file that contains multiple classes?

Best Answer

My advice: avoid files containing multiple classes and name files==classes even if you mean there are too many files. Try to organize them in folders. In very special cases you might have nested classes. In this case it makes sense separating the main class and a nested class into different files having one partial class. In this case I use following naming convention.

MyEnumerable.cs
MyEnumerable.MyEnumerator.cs

Probably you can also use multipart file names in your case.