C# class file name

In Java, the class name and the file name of the class must match.
In C#, this does not appear to be the case, ie I can have a file named MyClass.cs with:
public class NotMyClass {
}
Is this correct?
LVL 1
allelopathAsked:
Who is Participating?
 
Paul MacDonaldDirector, Information SystemsCommented:
Yes.
0
 
allelopathAuthor Commented:
Is this often done?
or is it best practices to have the class and file name match?
0
 
Paul JacksonSoftware EngineerCommented:
Some people have more than one class in a class file so often in this scenario the class file will be called something different.
In my opinion however it is better to have the class file and class name matching and only one class per class file.
0
 
Paul MacDonaldDirector, Information SystemsCommented:
I'm not aware of any standard, so I think it's a matter of personal preference.  Obviously, finding what you're looking for is important so bing smart about it makes sense.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.