[C#]写自己的类库

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

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

 

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


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

 

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

 

[csharp]  view plain copy
    1. Test.main mytest=new Test.main();  
    2. MessageBox.show(mytest.hello());  

你可能感兴趣的:(C#)