SoFunction
Updated on 2025-03-01

How to generate DLL files in C#

This article describes the method of generating DLL files in C#. Share it for your reference. The specific analysis is as follows:

Visual C# generates DLL files

DLL files written in programming languages ​​such as VisualC, Delphi or VB are generated after compilation, which is a binary file that can be used directly for computer use. However, although managed code generated by Visual C# compiler is also a binary file, it is not the original code that can be used directly for computer use. It is essentially an intermediate language (IL) code that needs to be compiled through the "Next Generation Windows Services" (Next Generation Windows Services, abbreviated as NGWS) runtime instant compiler (i.e. JIT).
The DLL files generated using Visual C# are already fundamentally different from previous DLL files. DLL files generated using Visual C# are more manifested as a class or class library in programming.

Make a component

1. First create a new class library project file
File->New->Project->Visual C# Projects->Class Library. Fill in the project file name and select the directory where the file is to be stored.
2. Project documents
Change the name of the file you want to create: and fill in the code.
3. Generate DLL file
Compile the project file: csc /target:library /out: Generate the component, which will be in the bin\debug directory of the project file, and the file extension is dll.

Test DLL

1. Create a new control application
File->New->Project->Visual C# Projects->Console Application. Test our components with this control application. 2. Add a reference to Namespace
Project->Add reference, browse to the DLL you just generated, and press OK. The reference will be added to the current project file class.
3. Call the myDll namespace, create the myDll object, and call its methods and properties
(1) Use namespace: using myDll;
(2) Create a myDll object;
(3) Call methods and properties.

DLL content:

using System;
using ;
using ;
using ;
namespace DZTT
{
 public class Operate
 {
  public int getSum(int a, int b)
  {
   return a + b;
  }
 }
}

How to use:

using System;
using ;
using ;
using ;
using DZTT;
namespace TestDll
{
 class Program
 {
  static void Main(string[] args)
  {
   Operate operate = new Operate();
   int c = (10 ,20);
   (());
  }
 }
}

I hope this article will be helpful to everyone's C# programming.