这个bbs类很简单,有四个私有变量,对应四个只读属性,方法只有一个带参数的构造函数,作用是从数据库中读取相应的数据,填充四个私有变量。类构造好了,让我们看看如何使用,在需要显示论坛这些属性的页面文件里(.aspx)里,构造四个Label,象这样: 
  <table width=140 cellpadding=4 cellspacing=1 border=0> 
  <tr> 
  <td class=cn>
  <font color=white>注册用户数:</font> 
  </td> 
  <td> 
  <asp:label id="lblUserCount" runat=Server
class=cn></asp:label>
  </td> 
  </tr> 
  <tr> 
  <td class=cn> 
  <font color=white>贴子总数:</font> 
  </td> 
  <td> 
  <asp:label
id="lblTopicCount" runat=Server
class=cn></asp:label>
  </td> 
  </tr> 
  <tr> 
  <td class=cn>
  <font color=white>版面数:</font> 
  </td> 
  <td> 
  <asp:label
id="lblForumCount" runat=Server
class=cn></asp:label>
  </td> 
  </tr> 
  </table> 
  然后在对应的c#文件里这样使用: 
   
  protected void Page_Init(object
sender, EventArgs e) 
  { 
  // 
  // CODEGEN: This call is required by the ASP+ Windows Form
Designer. 
  // 
  InitializeComponent();
   
  //初始化页面对象 
  //创建bbs对象 
  try 
  { 
  m_objBBS = new
BBS("鹰翔山庄论坛")
; 
  } 
  catch(Exception exp) 
  { 
  #if DEBUG 
  Response.Write
("初始化bbs对象出错:" + exp.Message + "<br>") ; 
  return ; 
  #endif//DEBUG 
  Server.Transfer("error.aspx") ; 
  } 
   
  //论坛名称 
  lblBBSName.ForeColor
= Color.White ; 
  lblBBSName.Text = m_objBBS.Title
; 
   
  //用户数 
  lblUserCount.ForeColor
= Color.White ; 
  lblUserCount.Text = m_objBBS.UserCount.ToString()
; 
   
  //文章数 
  lblTopicCount.ForeColor
= Color.White ; 
  lblTopicCount.Text = m_objBBS.TopicCount.ToString()
; 
   
  //版面数 
  lblForumCount.ForeColor
= Color.White ; 
  lblForumCount.Text = m_objBBS.ForumCount.ToString()
; 
  } 
   
  看出这样使用的好处吗?对,就是业务逻辑和html代码分开,这样无论页面原型如何修改,代码都不需要做丝毫改动。bbs对象构造好了,让我们看看论坛的其他对象,他们分别是用户(BBSUser)、版面(Forum)和贴子(Topic) , 我将在下节的内容里详细解释。