本文介绍了在不同的文件的C#类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该为我的C#项目每个类获得它自己的文件(在您看来)?

Should each class in my C# project get its own file (in your opinion)?

推荐答案

虽然每个文件的政策一个类在Java中严格执行,这不是要求的C#。然而,这通常是一个好主意。

While the one class per file policy is strictly enforced in Java, it's not required by C#. However, it's generally a good idea.

我通常打破这个规则,如果我有一个仅由主类很小的辅助类,但我preFER做,作为一个嵌套的内部类为清楚起见。

I typically break this rule if I have a very small helper class that is only used by the main class, but I prefer to do that as a nested inner class for clarity's sake.

但是,您可以使用部分分裂一个类成多个文件。这从向导生成的code分离的code是很有用的。

You can however, split a single class into multiple files using the partial keyword. This is useful for separating your code from wizard-generated code.

这篇关于在不同的文件的C#类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 14:55