How to use separate .cs files in C#?

后端 未结 7 474
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 00:55

Forum; I am a newbie working out a bit of code. I would like to know the best way to use separate .cs files containing other classes and functions. As an example of a basic func

7条回答
  •  独厮守ぢ
    2021-02-02 01:23

    In general you shouldn't put your code in the MainForm.designer.cs file. The *.designer.cs files are used by Visual Studio to wire up all of the tedious plumbing of actually put controls on the form.

    Any code that you want to use to interact with controls on the form should go MainForm.cs file. So if you want a function to clear controls on the form then you should place the code there.

    If you the code that you are writing clear the controls on the form is reusable in other projects then you should put it in another .cs file that can be linked into other projects.

    As Chris said, generally placing one class per .cs file is also a good idea. When you do, the file should have the name of the class it contains. So if you have a class named MyButtonHelpers then the source file should be named MyButtonHelpers.cs.

提交回复
热议问题