本人学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());
}
}
}
}
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]