1: using system; 2: using system.net; 3: using system.io; 4: using system.text; 5: 6: /// class to tear a webpage from a webserver 7: public class requestwebpage 8: { 9: private const int buffer_size = 128; 10: 11: /// m_strurl stores the url of the webpage 12: private string m_strurl; 13: 14: /// requestwebpage() is the constructor for the class 15: /// when called without arguments. 16: public requestwebpage() 17: { 18: } 19: 20: /// requestwebpage(string strurl) is the constructor for the class 21: /// when called with an url as parameter. 22: public requestwebpage(string strurl) 23: { 24: m_strurl = strurl; 25: } 26: 27: public string url 28: { 29: get { return m_strurl; } 30: set { m_strurl = value; } 31: } 32: 33: /// the getcontent(out string strcontent) method: 34: /// included in the class 35: /// uses variable 36: /// used to retrieve the content of a webpage. the url 37: /// of the webpage (includinghttp://) must already be 38: /// stored in the private variable m_strurl. 39: /// to do so, call the constructor of the requestwebpage 40: /// class, or set its property to the url string. 41: /// 42: /// 43: /// 44: /// 45: /// 46: /// 47: /// 48: /// 49: 50: public bool getcontent(out string strcontent) 51: { 52: strcontent = ""; 53: // ... 54: return true; 55: } 56: }
/// stores the url from the parameter /// in /// the private variable . public requestwebpage(string strurl)
在清单9.6中,你可以看到所有的这些以及前面的标签正在起作用。
清单9.6 为文档添加一个备注和bullet list
1: using system; 2: using system.net; 3: using system.io; 4: using system.text; 5: 6: /// class to tear a webpage from a webserver 7: /// the class requestwebpage provides: 8: /// methods: 9: /// 10: /// constructor 11: /// or 12: /// 13: /// 14: /// 15: /// 16: /// properties: 17: /// 18: /// 19: /// 20: /// 21: /// 22: /// 23: /// 24: public class requestwebpage 25: { 26: private const int buffer_size = 128; 27: 28: /// m_strurl stores the url of the webpage 29: private string m_strurl; 30: 31: /// requestwebpage() is the constructor for the class 32: /// when called without arguments. 33: public requestwebpage() 34: { 35: } 36: 37: /// requestwebpage(string strurl) is the constructor for the class 38: /// when called with an url as parameter. 39: /// stores the url from the parameter in 40: /// the private variable . 41: public requestwebpage(string strurl) 42: { 43: m_strurl = strurl; 44: } 45: 46: /// sets the value of . 47: /// returns the value of . 48: public string url 49: { 50: get { return m_strurl; } 51: set { m_strurl = value; } 52: } 53: 54: /// the getcontent(out string strcontent) method: 55: /// included in the class 56: /// uses variable 57: /// used to retrieve the content of a webpage. the url 58: /// of the webpage (includinghttp://) must already be 59: /// stored in the private variable m_strurl. 60: /// to do so, call the constructor of the requestwebpage 61: /// class, or set its property to the url string. 62: /// 63: /// retrieves the content of the webpage specified in 64: /// the property and hands it over to the out 65: /// parameter . 66: /// the method is implemented using: 67: /// 68: /// the method. 69: /// the method. 70: /// the method 71: /// the method 72: /// the method 73: /// the property together with its 74: /// method 75: /// the method for the 76: /// object. 77: /// 78: /// 79: /// 80: public bool getcontent(out string strcontent) 81: { 82: strcontent = ""; 83: // ... 84: return true; 85: } 86: }
9.2.3 提供例子 要想说明一个对象和方法的用法,最好的办法是提供优秀源代码的例子。因此,不要诧异文档注释也有用于声明例子的标签: and 。 标签包含了包括描述和代码的整个例子,而 标签仅包含了例子的代码(令人惊讶)。 清单9.7 说明如何实现代码例子。包括的例子用于两个构造函数。你必须给getcontent方法提供例子。
清单.7 利用例子解释概念
1: using system; 2: using system.net; 3: using system.io; 4: using system.text; 5: 6: /// class to tear a webpage from a webserver 7: /// ... 8: public class requestwebpage 9: { 10: private const int buffer_size = 12