本人学Asp.Net不久,用的是C#写代码,在学习C#中发现很多初学者对继承和多态性不是特别的了解,因此作了这个例子,希望对您有所帮助,例子很简单

页面文件TestProfileClass2.aspx
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" Src="profile2.cs" %>
<%@ Import Namespace="shai" %>
<html>
<head>
<style>
div"c#" runat="server">
public void Page_Load(Object sender,EventArgs e)
"<u>Profile Class</u><br>";
  message.InnerHtml += "Firstname:"+profile.getFirstname()+"<br>";
  message.InnerHtml += "Lastname:"+profile.getLastname()+"<br>";
  message.InnerHtml += "Phone:"+profile.getPhonenumber()+"<br><br>";

  profile.save();

  ExtendedProfile extendedprofile = new ExtendedProfile();
  message.InnerHtml += "<u>ExtendedProfile Class</u></br>";
  message.InnerHtml += "Firstname:"+profile.getFirstname()+"<br>";
  message.InnerHtml += "Lastname:"+profile.getLastname()+"<br>";
  message.InnerHtml += "Phone:"+extendedprofile.getPhonenumber()+"<br>";
  message.InnerHtml += "Address1:"+extendedprofile.getAddress1()+"<br>";
  message.InnerHtml += "Address2:"+extendedprofile.getAddress2()+"<br>";
  message.InnerHtml += "City:"+extendedprofile.getCity()+"<br>";
  message.InnerHtml += "State:"+extendedprofile.getState()+"<br>";
  message.InnerHtml += "Postal:"+extendedprofile.getPostal()+"<br>";
  message.InnerHtml += "Description:"+extendedprofile.getDescription()+"<br>";

  extendedprofile.save();
"Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body style="font:Arial, Helvetica, sans-serif ">
<b><h3>简单的继承/多态例子</h3></b><br><br>
object output:<br>
<br>
<div id="message" runat="server" />
</body>
</html>


类定义文件profile2.cs
using System;
using System.IO;
using System.Xml;
namespace shai     //名称空间shai
"Saidy";
   _lastname = "Chen";
   _phonenumber = "(010)88716990";
 "D:\\myweb2\\profile2.txt",FileMode.Create,FileAccess.Write);
   StreamWriter sw = new StreamWriter(fs);
   sw.WriteLine("Firstname:"+_firstname.ToString());
   sw.WriteLine("Lastname:"+_lastname.ToString());
   sw.WriteLine("Phone:"+_phonenumber.ToString());
   sw.Flush();
   sw.Close();
   fs.Close();
  "清华大学";
   _address2 = "清华大学物理实验室";
   _city = "北京";
   _state = "北京";
   _postal = "100024";
   _description = "教授";
 "d:\\myweb2\\saidy.xml";
   XmlTextWriter writer = null;           //保存为一个Xml文件
   try
   "Profile",null,null,null);            //表示<!DOCTYPE Profile>
    writer.WriteStartElement("Profile");                         //生成根元素  
    writer.WriteElementString("firstname",_firstname);   //生成子元素  <firstname>_firstname</firstname>
    writer.WriteElementString("lastname",_lastname);
    writer.WriteElementString("phonenumber",_phonenumber);
    writer.WriteElementString("address1",_address1);
    writer.WriteElementString("address2",_address2);
    writer.WriteElementString("city",_city);
    writer.WriteElementString("state",_state);
    writer.WriteElementString("postal",_postal);
  writer.WriteEndElement();
  writer.Flush();
  writer.Close();
   "Exception:",ee.ToString());
   }
 }
}
}

标签:
|给A|As|sp|pN|Ne|et|t初|初学|学者|者的|的关|关于|于继|继承|承和|和多|多态|态性|性的|的例|例子|子|

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com