Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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! A folder by any other name!

THIS IS WHAT I AM LOOKING FOR

enter image description here

THIS IS WHAT I AM PRESENTED WITH

enter image description here

like image 529
Mr Heelis Avatar asked Aug 06 '14 12:08

Mr Heelis


People also ask

What is the equivalent of Java package in C#?

Namespaces are the closest C# has to Java packages.

Does C# have packages like Java?

yes it has namespaces.... when ever you add new project to solution, it has its own namespace just like package in java.

Is assembly in C# same as package in Java?

No they are not same.

Do we have packages in C++?

Packages in C++: Namespaces C++ provides several types of scopes: global, file, class, and block. We can also create a package scope using a namespace declaration: namespace NAME { DECLARATION ... }


3 Answers

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.

Actually, packages in java are folders too.

like image 90
libik Avatar answered Sep 18 '22 22:09

libik


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:

namespace Foo.Bar
{
}

at the top of classes in that folder. Namespaces are the closest C# has to Java packages. They're not quite the same, as packages in Java also affect access control - but they're close.

like image 31
Jon Skeet Avatar answered Sep 22 '22 22:09

Jon Skeet


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.

like image 26
Subodh S Avatar answered Sep 21 '22 22:09

Subodh S