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中,你可以看到所有的這些以及前面的標(biāo)簽正在起作用。
清單9.6 為文檔添加一個(gè)備注和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 提供例子 要想說(shuō)明一個(gè)對(duì)象和方法的用法,最好的辦法是提供優(yōu)秀源代碼的例子。因此,不要詫異文檔注釋也有用于聲明例子的標(biāo)簽: and 。 標(biāo)簽包含了包括描述和代碼的整個(gè)例子,而 標(biāo)簽僅包含了例子的代碼(令人驚訝)。 清單9.7 說(shuō)明如何實(shí)現(xiàn)代碼例子。包括的例子用于兩個(gè)構(gòu)造函數(shù)。你必須給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