Generally speaking, these should be the same. The good practice standard is that every file contains exactly one class/interface/... and thus it makes sense to name the file after that one class/interface/... This is exactly why Visual Studio offers to rename the class when you rename the file (if the class and file name were the same).
That being said, exceptions do exist, but they are contextual considerations and are open to subjective discussion. Some people will refute any exception and will religiously stick to the good practice standard as a matter of style. Others will allow for reasonable exception. I'm in the latter group, and I'm just listing reasonable exceptions that I've encountered:
- In a project with many small enums (that were functionally very tightly coupled), those enums were contained in a single file (there were several of these grouped files). The reason is that different projects used different sets of enums; the files were used as "enum groups" so developers had an idea which enums were to be used in conjunction with one another.
- In my current project, test classes differ from their filenames by using underscores to split words, to enhance readability in the Test Explorer (= class name) while keeping the VS editor tab width (= filename) shorter.
That being said, it needs to be remarked that these exceptions are contextual and extremely rare.
It is accepted that partial classes are a special case as these, by definition, exists in different files that must have different file names.
Not quite "must". The multiple parts of a partial class can live in different directories, thus allowing for the same filename to be reused.
But overall, there are indeed cases where you do vary the filenames so you can highlight which part of the partial class each file addresses, e.g. MyPartialClass_generated.cs
versus MyPartialClass.cs
(which is the most common scenario for partial classes, in my experience)
Is this just a style thing, or does it serve some other purpose/intent?
There is no technical reason to do this (other than avoiding duplicate filenames in the same directory). It's usually a matter of logical inevitability (e.g. multiple classes in file) or a matter of human readability (like the underscore example I listed).