.NET命名空间

编程入门 行业动态 更新时间:2024-10-23 21:39:50
本文介绍了.NET命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的背景主要是作为Java开发人员,但最近我一直在.NET中进行一些工作.因此,我一直在尝试在家中做一些简单的项目,以更好地使用.NET.我已经能够将我的大部分Java经验转移到使用.NET(特别是C#)中,但是真正困扰我的是名称空间.

My background is primarily as a Java Developer, but lately I have been doing some work in .NET. So I have been trying to do some simple projects at home to get better at working with .NET. I have been able to transfer much of my Java experience into working with .NET (specifically C#), but the only thing that has really perplexed me is namespaces.

我知道名称空间与Java软件包相似,但据我所知,主要区别在于,对于Java软件包,它们使用实际的文件夹来显示分隔,而在.NET中则不,所有文件都驻留在其中.一个文件夹,然后在每个类中简单声明名称空间.

I know namespaces are similar to Java packages, but as from what I can tell the main difference is that with Java packages they use actual file folders to show the seperation, while in .NET it does not and all the files reside in a single folder and the namespace is simply declared in each class.

我觉得很奇怪,因为我总是将软件包视为组织和组合相关代码的一种方式,从而使浏览和理解变得更加容易.由于在.NET中,这种方式无法正常工作,因此超时工作会使项目显得人满为患,而且导航也不那么容易.

I find this odd, because I always saw packages as a way to organize and group related code, making it easier to navigate and comprehend. Since in .NET it does not work this work this way, overtime, the project appears more overcrowded and not as easy to navigate.

我在这里错过了什么吗?我必须这样.我应该将事情分解成解决方案中的单独项目吗?还是有更好的方法将类和文件保持在项目中?

Am I missing something here? I have to be. Should I be breaking things into separate projects within the solution? Or is there a better way to keep the classes and files organized within a project?

正如布莱尔指出的那样,这几乎是问此处.

As Blair pointed out this is pretty much the same question asked here.

推荐答案

我不能说这是最佳实践,但是我经常看到文件以反映名称空间的目录层次结构组织.如果它更适合您的代码思维模式,那就这样做-我认为没有什么害处.仅仅因为.NET模型没有在名称空间,项目和目录结构之间强制执行关系,并不意味着您就无法拥有这样的关系.

I can't claim that it's a best practice, but I often see files organized in a directory hierarchy that mirrors the namespace. If it fits your mental model of the code better, then do so - I can't think of any harm. Just because the .NET model doesn't enforce relationships between namespaces, projects, and directory structure doesn't mean you can't have such relationships if you want to.

将代码拆分成更多项目而不是您需要的一点,因为这会减慢编译速度,并在您必须管理多个程序集时增加一些开销.

I'd be a little leery of breaking up the code into more projects than you need, as this can slow compilation and add a little bit of overhead when you have to manage multiple assemblies.

请注意,此问题几乎与解决方案中的文件夹应该与名称空间匹配吗?

Note that this question is nearly a duplicate of should the folders in a solution match the namespace?

更多推荐

.NET命名空间

本文发布于:2023-11-09 06:00:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571575.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空间   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!