How do you create a library of commonly used structs, enumerationsconstants and functions using C#

B

Bit Byte

Coming from a pure C/C++ background - recently started looking at C# for
a project. The absence of header files in C# has thrown me "a bit of a
curve".

I want to modularise my code and put all the commonly used data types
etc into a single compilation unit (library). How may I do this in C# -
any examples would be useful - tx
 
J

Jon Skeet [C# MVP]

Bit Byte said:
Coming from a pure C/C++ background - recently started looking at C# for
a project. The absence of header files in C# has thrown me "a bit of a
curve".

I want to modularise my code and put all the commonly used data types
etc into a single compilation unit (library). How may I do this in C# -
any examples would be useful - tx

Just create a class library project, and then add a reference to it
from other projects.
 
B

Bruce Wood

Coming from a pure C/C++ background - recently started looking at C# for
a project. The absence of header files in C# has thrown me "a bit of a
curve".

I want to modularise my code and put all the commonly used data types
etc into a single compilation unit (library). How may I do this in C# -
any examples would be useful - tx

C# uses DLLs the way that C++ would use header files. The compiler
examines the contents of a DLL, part of which is a manifest that
contains definitions for all of the publicly available types,
including method call signatures.

So, just create a separate project for your common library, put all of
your common stuff in it, and build it into a DLL.

Then, when you want to use it in another project, just use Add
Reference in that project to add a reference to the DLL that you
created in the library project. Your client project will then "know
about" all of the public types in the library.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top