public and private variable (C#) : Access Control « Development « ASP.Net






public and private variable (C#)

<%@ page Language="c#" runat="server" %>
<script language="c#" runat="server">
  public class User
  {
    static private int count;
    static public int Count
    {
      get
      {
        return count;
      }
    }
    public User() 
    {
      count++;
    }
    static User()
    {
       count = 0;
    }
  }
  void Page_Load() 
  {
    Response.Write("User Count = " + User.Count);
    Response.Write("<hr/>Creating User Alex.");
    User Alex = new User();
    Response.Write("<br/>User Count = " + User.Count);
    Response.Write("<hr/>Creating User Rob.");
    User Rob = new User();
    Response.Write("<br/>User Count = " + User.Count);
    Response.Write("<hr/>Creating User Jake.");
    User Jake = new User();
    Response.Write("<br/>User Count = " + User.Count);
  }
</script>

           
       








Related examples in the same category