How to create a DLL from a C# namespace with Mono

In order to create a DLL we will use a crude example (probably meaningless). But the important thing is to know the commands for create a DLL.

The DLL will be created from a simple class used to generate random numbers with congruential generators. What is most striking in the code is a class named CongruentialGenerator with a the public method MixedMethod and a read-only property named Box:

Random.cs
Random.cs

Create the DLL

The way to create the DLL is with the next command: gmcs /target:library /out:Rand.dll Random.cs . If you are using .NET Framework you must change gmcs by csc.

Calling the DLL

Now we can to call the DLL generated like a namespace:

Main.cs
Main.cs

The way to create a executable file is with the next command: gmcs /reference:Rand.dll Main.cs. If you are using .NET Framework you must change gmcs by csc.

Now we simply run the Main.exe file generated: mono Main.exe :

Execution
Execution

Now this DLL can be used by any other programming language running over .NET platform, e. g. IronPython, Visual C++, etc.

2 comentarios sobre “How to create a DLL from a C# namespace with Mono

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s