The following is the command to compile dllsource.cs as a dynamic link library instead of the executable file:

$ mcs /target:library dllsource.cs

We can also specify a different name of the binary with the /out option. For example:

$ mcs /target:library /out:mylibrary.dll dllsource.cs

Finally, if we want to compile a souce which depends on a dll file, we need to use the /reference option.

$ mcs example.cs /reference:mylibrary.dll

Note: mcs is the mono compiler. If you use Microsoft C# compiler, just replace mcs with csc.