简体   繁体   中英

Does C# have anything like package in java

I'm new in C# and I'm now coding with Visual Studio 2013.

I'm developing a project and it can be divided into several functions.

When I want to separate the code into different packages like what I did with Java, I find that Visual Studio only offer me to create a new project in the same solution.

So does C# have anything like package in java? So that I can place my source properly. Or the project itself is just like packages in java?

Thank you very much!

No, C# has namespaces. You can normally wrap objects (classes, enums, structs, etc) in namespaces

namespace Whatever
{
    public class ClassA{}
    public struct StructA{}
}

Then to instantiate a ClassA do the following...

Whatever.ClassA _classA = new Whatever.ClassA();

You can also at a "using" directive so you don't have use the namespace all the time in your code file....

using Whatever;

ClassA _classA = new ClassA();

Hope it helps, Leo

I think you are trying to separate some sort of code from other. you can use namespaces for doing that.

please find below link.

http://msdn.microsoft.com/en-us/library/z2kcy19k.aspx

As MSDN state:

The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types.

Instead of package c# using namespace.

for java you use the jar file here dll.using the namespace you can access the dll's.

you can separate the class file using the folder also.you need to create the folder under the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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