C# .cs file name and class name need to be matched?

后端 未结 4 1244
后悔当初
后悔当初 2020-12-20 11:23

In Java the file name must be the public class name defined in that java file. Does C# has similar requirement? can I have a A.cs file which only defines a public Class B in

4条回答
  •  鱼传尺愫
    2020-12-20 11:44

    No, in C# you don't have to name your class the same as your file.

    Along a similar line, you can have multiple public classes in on file. Java only lets you have one.

    This can be helpful for defining a few public enums in one file. Of a few small classes.

    It is bad practice however to throw too much into one file.

提交回复
热议问题