本人学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());
   }
 }
}
}

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!