代码如下
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 - b; } } }
csc.exe /out:MyClassLib.dll /t:library Calculator.cs
/t:library是生成一个类库文件
代码如下
using System; using MyClassLib; namespace MyConsoleApp { class Program { static void Main(string[] args) { Console.Write("请输入第一个整数:"); int number1 = Convert.ToInt32(Console.ReadLine()); Console.Write("请输入第二个整数:"); int number2 = Convert.ToInt32(Console.ReadLine()); Calculator cal = new Calculator(); Console.WriteLine("{0} + {1} = {2}",number1,number2,cal.Add(number1,number2)); Console.WriteLine("{0} - {1} = {2}", number1, number2, cal.Sub(number1, number2)); Console.ReadKey(); } } }
csc.exe /out:Program.exe /t:exe /r:MyClassLib.dll Program.cs
/r:MyClassLib.dll是对该.dll文件的引用
《CRL Via C#》使用CSC.exe对两个文件进行编译
原文地址:http://lsieun.blog.51cto.com/9210464/1753487