Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i use classes and objects in different projects in same solution.
Is it work with importing namespace ?
Posted

Add a reference to the project that contains them and then add using directive at the top of the code where you want to reference that namespace.
Hey presto the classes/objects (aslong as they are public) should accessible.
 
Share this answer
 
Yes - and no.
First add a reference to the project containing the class in the project you want to use it in.
You can then use the Imports (VB) or using (C#) statement to make referencing easier.

Do note that you can't add a reference if it would create a circular reference chain: VS will complain if you try because it would become impossible to build the solution. In that case you need to create a new assembly which contains the common code and reference that from both the otehr projects.
 
Share this answer
 
Namespaces have nothing to do with importing or accessibility of types. "Projects" have nothing to do with accessibility of types.

Everything happens at the level of assemblies. Project is just source code which is compiled into assembly. If you have two assemblies, one can reference another one; it means that its name (or strong name) is mentioned in the PE file of referencing assembly. When some assembly is referenced, its public declarations (types and members, but also protected for members) become exactly as accessible as accessible as if they were in the same assembly.

This is information on using assemblies (and namespaces): http://msdn.microsoft.com/en-us/library/ms973231.aspx[^].

Many beginners asked questions about namespace wondering that using declarations cannot help to use assemblies. Maybe something is not so well explained in MSDN; just read it more carefully. You don't really need using; it is written just for convenience and shorthand naming; it you always used full type names, you could develop without using. This is just for naming of top-level types: they can have identical simple name and still differentiated by fully-qualified names.

Now, if you put all related projects to the same solution (highly recommended), you can reference by projects, using the tab "Projects" of the window "Add Reference". Even though ultimately the reference is done by the name of the main executable module of the referenced assembly (most typically, *.DLL, but it always can be *.EXE or any other file with .NET assembly manifest). This approach greatly improves development process, by a number of reasons.

You can get an idea about modules and there role in .NET here:
http://msdn.microsoft.com/en-us/library/168k2ah5%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/7d3c18c2%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900