|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
以前很热炒跨平台,主要是由于硅谷挑战微软霸主地位的热情,但是冷静下来后,跨平台往往不是那么一回事。假设你有个软件,所谓的跨平台,你只需要为第二个平台上重新编译一次就行了,这样很难么?asp.net|初学|承继自己学Asp.Net不久,用的是C#写代码,在进修C#中发明良多初学者对承继和多态性不是出格的懂得,因而作了这个例子,但愿对您有所匡助,例子很复杂
页面文件TestProfileClass2.aspx
<%@PageLanguage="C#"ContentType="text/html"ResponseEncoding="gb2312"Src="profile2.cs"%>
<%@ImportNamespace="shai"%>
<html>
<head>
<style>
div{font:Arial,Helvetica,sans-serif;
background-color:#cccccc;
border-color:black;
border-width:1;
border-style:solid;
padding:10,10,10,10;
}
</style>
<scriptlanguage="c#"runat="server">
publicvoidPage_Load(Objectsender,EventArgse)
{
Profileprofile=newProfile();
message.InnerHtml+="<u>ProfileClass</u><br>";
message.InnerHtml+="Firstname:"+profile.getFirstname()+"<br>";
message.InnerHtml+="Lastname:"+profile.getLastname()+"<br>";
message.InnerHtml+="Phone:"+profile.getPhonenumber()+"<br><br>";
profile.save();
ExtendedProfileextendedprofile=newExtendedProfile();
message.InnerHtml+="<u>ExtendedProfileClass</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();
}
</script>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<title></title>
</head>
<bodystyle="font:Arial,Helvetica,sans-serif">
<b><h3>复杂的承继/多态例子</h3></b><br><br>
objectoutput:<br>
<br>
<divid="message"runat="server"/>
</body>
</html>
类界说文件profile2.cs
usingSystem;
usingSystem.IO;
usingSystem.Xml;
namespaceshai//称号空间shai
{
interfaceISaveData//界说一个接口ISaveData,他作为Profile的基类被承继,因为其有多态性的特性,能够被
{//分歧类挪用个中的办法,并修正
voidsave();
}
publicclassProfile:ISaveData//界说类Profile
{
protectedstring_firstname;//内里包括三个属性,分离为_firstname、_lastname、phonenumber
protectedstring_lastname;
protectedstring_phonenumber;
publicProfile()//为属性界说个中的初始值
{
_firstname="Saidy";
_lastname="Chen";
_phonenumber="(010)88716990";
}
publicstringgetPhonenumber()//Profile类中的办法getPhonenumber()
{
return_phonenumber;
}
publicvirtualvoidsetPhonenumber(stringphonenumber)
{
_phonenumber=phonenumber;
}
publicstringgetFirstname()//Profile类中的办法getFirstname()
{
return_firstname;
}
publicvoidsetFirstname(stringfirstname)
{
_firstname=firstname;
}
publicstringgetLastname()//Profile类中的办法getLastname()
{
return_lastname;
}
publicvoidsetLastname(stringlastname)
{
_lastname=lastname;
}
publicvirtualvoidsave()//挪用ISaveData接口的save()办法
{
//保留数据为Text格局
FileStreamfs=newFileStream("D:myweb2profile2.txt",FileMode.Create,FileAccess.Write);
StreamWritersw=newStreamWriter(fs);
sw.WriteLine("Firstname:"+_firstname.ToString());
sw.WriteLine("Lastname:"+_lastname.ToString());
sw.WriteLine("Phone:"+_phonenumber.ToString());
sw.Flush();
sw.Close();
fs.Close();
}
}我有个同学,他是搞Java的,他给我说“Java不是效率低,而是速度慢。”,我不是搞Java的,我实在想不透这句话的含义,难道执行速度不就是效率低吗?难道执行速度慢还成效率高了? |
|