C # Creating DLL files for program call methods
To create a dynamic DLL file method using C #:
1. In the VS2017 environment, new-project-Select the class library type;
2. Create a new. cs file (such as Test.cs) and write the following code:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespaceTestdll8 {9 Public classTestTen { One Private intA; A Private intb; - - PublicTest (intAintb) the { - This. A =A; - This. B =b; - } + - Public intAdd () + { A returnA +b; at } - - Public intAddintXinty) - { - returnX +y; - } in - } to}
3. Click on the project-right-rebuild, open the folder-find the Debug folder, there is TestDll.dll file
4. Calling the TestDll.dll file method in the program
A. Add TestDll.dll to the reference and invoke the instance as:
1 using Testdll; 2 3 // instantiating an object 4 New Test (35); 5 // Call method 7MessageBox.Show (Test.add (). ToString ()); 8 MessageBox.Show (Test.add (5,5). ToString ());
C # Creating DLL files for program call methods