简体   繁体   English

Visual Studio中表单的命名空间

[英]Namespace of Forms in Visual Studio

Is it safe to put every form in my presentation-layer in the same namespace? 将每种表单放在我的表示层的同一命名空间中是否安全? (Might be a stupid question but i want to be sure). (可能是一个愚蠢的问题,但我想确定)。

Namespaces are to organize your code. 命名空间将组织您的代码。 If you have a few forms and you put them all in the same namespace, that is okay. 如果您有几种形式,并将它们全部放在同一个名称空间中,那就可以了。

I would say if you have tons of screens, you eventually will lose overview of the code, and then it becomes important to organize your code. 我想说的是,如果您有大量的屏幕,最终将失去对代码的概述,那么组织代码就变得很重要。 Usually you will split on funtionality, like DataLayer , PresentationLayer , etc., but you can do that for screen categories too (like User , Article ). 通常,您会在功能上进行划分,例如DataLayerPresentationLayer等,但是您也可以针对屏幕类别(例如UserArticle )进行拆分。

To be clear, there is nothing safe or unsafe about using namespaces. 需要明确的是,使用名称空间并没有安全或不安全的地方。

It's not unsafe . 这不是不安全的

The purpose of namespaces is to: 命名空间的目的是:

  • avoid running out of names (which must be unique), and 避免用尽名称(名称必须唯一),并且
  • avoid confusion between similarly named things. 避免名称相似的事物之间的混淆。

For example, there are lots of things in lots of libraries with classes called "Node", "Record", "Entry", "Rule" or similar generic terms. 例如,许多库中有很多东西,它们的类称为“节点”,“记录”,“条目”,“规则”或类似的通用术语。

In general, if you always use two classes together and never apart, there is usually no reason to put them in different namespaces. 通常,如果您始终将两个类一起使用且永不分开,则通常没有理由将它们放在不同的命名空间中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM