黑马程序员_继承

继承
子类继承父类后,子类就拥有了父类的属性和方法
1.
class Program
{
       static void Main(string[] args)
       {
               DongBei DB=new DongBei();
               DB.Man="高大,豪爽";
               DB.Do();

               ShangHai SH=new ShangHai();
               SH.Man="小男人,抠门"
               Console.ReadKey();
       }
}
class Person
{
       public string Man{ set; get;}
       public string Woman{ set; get;}

       public void Do()
       {
               Console.WriteLine("{0}",this.Man)
       }
}
class DongBei()
{

}
class ShangHai()
{

}

2.用于判断用户是否登录

AdminBasePage类
public class AdminBasePage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["adminuser"] == null)
            {
                Response.Write("<script type='text/javascript'>alert('请先登录');this.top.location='AdminLogin.aspx';</script>");
                Response.End();
                return;
            }
        }
    }

AdminIndex.aspx页面继承于AdminBasePage类之后,就能判断用户是否登录而作出相应的反映
public partial class AdminIndex : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }

 

 

posted @ 2013-04-16 18:35  微笑的小鸟  阅读(148)  评论(0编辑  收藏  举报