1. Create a new Calculator.cs file
The code is as follows
Using System;namespace myclasslib{public class Calculator {public int Add (int a, int b) { return a + B; } public int Sub (int a, int b) {return a-A; } }}
2, compile the Calculator.cs, generate the MyClassLib.dll file
Csc.exe/out:myclasslib.dll/t:library Calculator.cs
/t:library is to generate a class library file
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7D/C3/wKioL1bvozXSif3NAAAidUlXhmA992.png "title=" Calculator_cs_lib.png "alt=" Wkiol1bvozxsif3naaaidulxhma992.png "/>
3. Create a new Program.cs file
The code is as follows
Using system;using myclasslib;namespace myconsoleapp{ class program { static void main (string[] args) { console.write ( "Please enter the first integer:"); int number1 = convert.toint32 (Console.ReadLine ()); console.write ("Please enter a second integer:"); int number2 = convert.toint32 (Console.ReadLine ()); calculator cal = new calculator (); &nbsP; console.writeline ("{0} + {1} = {2}", number1,number2,cal. ADD (number1,number2)); Console.WriteLine ("{0} - {1} = {2}", number1, number2, cal. Sub (number1, number2)); Console.readkey (); } }}
4, compile the Program.cs, generate the Program.exe file
Csc.exe/out:program.exe/t:exe/r:myclasslib.dll Program.cs
/r:myclasslib.dll is a reference to the. dll file
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7D/C3/wKioL1bvpdqwaufIAAAzx2567is495.png "title=" Program_cs_exe.png "alt=" Wkiol1bvpdqwaufiaaazx2567is495.png "/>
5. Program Operation result
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7D/C7/wKiom1bvpXDCnrmTAAAHbrFlNeA966.png "title=" Program_exe_result.png "alt=" Wkiom1bvpxdcnrmtaaahbrflnea966.png "/>
CRL Via C # uses CSC.exe to compile two of files