简体   繁体   English

相当于C#中的java包

[英]Equivalent to java packages in C#

I have been looking for a way to make a "package folder" in visual studio express 2013, the way I might do it in java is a "package" I know that I can make whole new projects called "Visual Studio Package Projects" via a wizards but all I really want is a ~container~ that puts a dot in the class name! 我一直在寻找一种在visual studio express 2013中制作“包文件夹”的方法,我在java中的方式是一个“包”我知道我可以通过名为“Visual Studio包项目”的全新项目一个巫师,但我真正想要的是一个〜容器〜在类名中添加一个点! A folder by any other name! 任何其他名称的文件夹!

THIS IS WHAT I AM LOOKING FOR 这就是我正在寻找的东西

在此输入图像描述

THIS IS WHAT I AM PRESENTED WITH 这就是我提出的问题

在此输入图像描述

If you create class inside folder, the namespace (which is almost the same as packages in Java) for this class is based on the folder(s) it is inside. 如果在文件夹内创建类,则此类的命名空间(与Java中的包几乎相同)基于它所在的文件夹。

Actually, packages in java are folders too. 实际上,java中的包也是文件夹。

Just add a new folder - then by default, new classes will be in that namespace. 只需添加一个新文件夹 - 然后默认情况下,新类将位于该命名空间中。 So for example, if you have a project called Foo , and you add a folder called Bar , then you'll end up with: 例如,如果您有一个名为Foo的项目,并且添加了一个名为Bar的文件夹,那么您将最终得到:

namespace Foo.Bar
{
}

at the top of classes in that folder. 在该文件夹的类顶部。 Namespaces are the closest C# has to Java packages. 命名空间是最接近Java包的C#。 They're not quite the same, as packages in Java also affect access control - but they're close. 他们是不太一样的,包在Java中也影响访问控制-但他们接近。

A folder can be created in a project root. 可以在项目根目录中创建文件夹。 And any number of nested folder can be created to categories common files. 并且可以创建任意数量的嵌套文件夹以分类常见文件。 And intended class can be placed inside that folder. 并且可以将目标类放在该文件夹中。 This way you can get ~container~ that puts . 这样你就可以得到〜容器〜。 in namespace used in class. 在类中使用的命名空间中。

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

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