Use a DLL file in C #

xiaoxiao2021-03-06  58

DLL (Dynamic Library), which has greatly improved our application in maintainability, code repeated utilization. Just like the EXE file compiled with C #, the DLL generated by the C # is substantially an intermediate language (IL) code, not local code. Generate a DLL file: // Define the namespace: Namespace mydll {// Define a class, inherit this class in the program: public class show {// Defines a method: public string appcopy () {return "Copyright: jeky.cn ";}}} Save the above code in the" D: / CS / "directory, the file name is:" mydll.cs ", compile: CSC /R :system.dll / T: library / out: d: / CS / MyDLL.DLL D: /CS/Mydll.cs calls the DLL file: use system; using system.drawing; using system.windows.forms; using mydll; // Import this name space

Public class myform: form {public static void main () {show1 = new show (); // Inherit this class messagebox.show (show1.appcopy ());}} Save the above code in "D: / CS / In the directory, the file name is: "Test.cs", compile: csc /r: //cs/mydll.dll /r: sTem.dll /out: //cs/test.exe d: / cs / Test.cs Result: In the "D: / CS /" directory, a TEST.EXE file is generated, double-click the dialog box message: "Copyright: jeky.cn", it is instantiated with the Show class, Then call a method appcopy () in the class, return a result of a string type. Oh, simple! ~

转载请注明原文地址:https://www.9cbs.com/read-91530.html

New Post(0)