How to implement your individual class into any project

VBBRett used Ask the Experts™
I am fully aware of how to create a class and a namespace, you just declare it at the top of your class file.  But let's say that I had a project where I created a merchant namespace and a shopping cart class and I wanted to use that namespace and class in another project or solution, how would I go about doing it?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
You just add a REFERENCE to your project.
First of all, You need to compile your class file into a .dll or .exe assembly file. Whenever you build your code that is automatically done for you. And the output .dll or .exe is stored in Project\..\bin\debug folder. Now when you have a new project go to solution explorer. Then right click on project and click on Add Reference. Then Browse to your .dll or .exe file, select that file and click ok. Now you get a reference to your class inside the new project. Then in the code editor add a using statement at the top of your .cs code file using your_namespace; .Here your_namespace is the name of the namespace you previously created in which ur class file resides. Thats it.. Then simply start coding Create object of your class and move on..


Thanks starlite551.  If I wanted to copy all the dll files that I created and put them in a folder to hold all of my classes for future reference called My Programmed Classes, could I do that as opposed to sorting and looking through all of my project folders?  That way for future reference I don't have to recall what project I held a class in?
Yes, you can keep the compiled files in one directory and use them as a reference anytime you wish to.

Another way to do it is that you register them with the Global Assembly Cache (GAC) in your system.
How to register an assembly in GAC using Gacutil.exe :

A tip: When you are deploying the project, set the .DLL Reference property "Copy To Local" to true.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial