1. generate dll
building .cs file, for example: myDll.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DZTT { public class Operate { public int getSum(int a, int b) { return a + b; } } }
enter vs menu->cmd
csc /target:library /out:myDll.DLL myDll.cs
2. building console project testDll
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DZTT; namespace TestDll { class Program { static void Main(string[] args) { Operate operate = new Operate(); int c = operate.getSum(10 ,20); Console.WriteLine(c.ToString()); } } }
3. Project->Add reference, add myDll.dll
ok.