[C#]写自己的类库

类库,就是我们所说的动态链接库(DLL)。在C#中,我们可以把我们做的一些类封装成一个类库,然后把类库模糊化处理,就可以共享给别人用了。

我们首先新建一个类 比如叫Test类,我们添加一个函数hello函数,返回字符串“test”。

[csharp]view plaincopy

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Test
  6. {
  7. public class main
  8. {
  9. public string hello()
  10. {
  11. return "test";
  12. }
  13. }
  14. }

然后我们在项目中添加引用,选择Test,添加,OK。

那么怎么用呢?就象这样:

[csharp]view plaincopy

    1. Test.main mytest=new Test.main();
    2. MessageBox.show(mytest.hello());