VS2012下实现类库,并调用。
1.创建类库
2.代码如下:
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using System.IO;
7
8 namespace ClassLibrary
9 {
10 public class Person
11 {
12 private string name;
13
14 public Person(string name)
15 {
16 this.name = name;
17 }
18
19 public void sayHello()
20 {
21 Console.WriteLine("Hello Everyone!");
22 }
23 }
24 }
3.生成解决方案(Build),在项目的DebugBin下可以找到生成的.dll
4.新建控制台应用项目
4.引用添加ClassLibrary.dll
5. 测试代码如下:
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6
7 namespace ClassLibraryTest
8 {
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 ClassLibrary.Person Jack = new ClassLibrary.Person("Jack");
14 Jack.sayHello();
15
16 Console.ReadKey();
17 }
18 }
19 }
6.运行成功: