Creating reusable code modules (e.g. C ++ style classes, headers) in C #

In C ++, you can create useful code modules by creating a class and issuing header and implementation files to developers who want to use your class.

I want to do this in C #, but I have little experience with the C # language. Basically, I need to create a class that can be reused by another C # programmer in Visual Studio 2010. I know that DLL references are one way to use other people's classes. Do I need to create a DLL to achieve what I want to achieve? Or are there other, better ways?

For example, let's say I create a Cow class that can "moo". In C ++, someone who uses my class will simply enable Cow.h, instantiate the Cow object myCow, and then call myCow.moo (). How can I achieve this simple task in C #?

Thanks for your time and patience.

+4
source share
3 answers

Yes, just create a Class Library project and share the resulting DLLs.

Other developers will just need to add a link to your DLL, after which they will be able to freely use any public objects from your library.

+3
source

This is the standard for creating dlls for distributing reusable code.

You can study the old school COM objects, but I would avoid them and just use a well-organized class library.

0
source

Of course, you can always exchange source files, but the recommended .Net way to distribute reusable code is a DLL. This allows developers to use any .Net language to use your code (they should not use the same language as your project).

It also simplifies project support. If you use the source code, it will most likely be harder to distribute updates than if you just needed to update one dll. If you have several projects that reference the same DLL, all of them can refer to it from the same location, and whenever the DLL is updated, all projects that use it will automatically use the updated dll the next time compilation of the project. You can also update the dll without recompiling projects that use it (although you cannot change the names / signatures of everything that is used by the project).

0
source

All Articles