求高手一个能顺利运行的满意解答!!!。。编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。编译器错误消息: CS0117: “ASP.aspnet_engine_object_aspx.Car”并不包含“MyEngine”的定义源错误:行 112: Engine MyEngine=new Engine("Xeer", "070","V6");
行 113:
行 114: AlexEngine=ShumaCar.MyEngine.Name;
行 115: RobEngine=ShumaCar.MyEngine.Name;
行 116: MyEngine=ShumaCar.MyEngine.Name;
修改以后还是不行啊,这个代码应该怎么改???<%@page language="C#" runat="server" Debug="true"%>
<script runat="server">
public class Engine
{
private string name;
private string rpm;
private string serialno;
public Engine(string Name, string Rpm, string SerialNo)//如果这里有参数名称,那么实例化一个engine的时候也要在括号内表明参数名称(并非参数)
{
name=Name;
rpm=Rpm;
serialno=SerialNo;
} public void SwitchOn()
{
if(Name=="Xeer" && Rpm=="070" && SerialNo=="V6")
{
return "The engine is running.";
}
else
{
return "The engine is not running.";
} }
}
public class Car
{
private string color;
private int gear;
private int ignition;
private Engine engine; public Engine objEngine
{
get
{
return engine;
}
set
{
engine=value;
}
}
public static int Count
{
get
{
return count;
}
}
public string Color
{
get
{
return color;
}
set
{
color=value;
}
}
public int Gear
{
get
{
return gear;
}
}
public void ChangeGear(int direction)
{
if(direction <0)gear-=1;
if(direction>0)gear+=1;
if(gear>5)gear=5;
if(gear <-1)gear=-1;
}
public void ChangeGear(string direction)
{
if(direction.ToLower()=="down")
{
ChangeGear(-1);
}
if(direction.ToLower()=="up")
{
ChangeGear(+1);
}
}
}
public void Page_Load()
{
Car ShumaCar=new Car();
ShumaCar.objEngine=new Engine("Xeer", "070","V6"); Engine AlexEngine=new Engine("Ferrari", "050", "V10");
Engine RobEngine=new Engine("Fdd", "060", "V3");
Engine MyEngine=new Engine("Xeer", "070","V6");
AlexEngine=ShumaCar.MyEngine.Name;
RobEngine=ShumaCar.MyEngine.Name;
MyEngine=ShumaCar.MyEngine.Name;
Response.Write(" <b>New object 'ShumaCar' created. </b>");
Response.Write(" <br/>Color:"+ShumaCar.Color);
Response.Write(" <br/>Gear:" +ShumaCar.Gear);
ShumaCar.Color="Black";
ShumaCar.ChangeGear(+1);
Response.Write(" <br/> <b>Properties updated. </b>");
Response.Write(" <br/>Color:" +ShumaCar.Color);
Response.Write(" <br/>New gear:"+ShumaCar.Gear);
ShumaCar.Color="Black";
ShumaCar.ChangeGear(+1);
Response.Write(" <br/> <b>Properties updated. </b>");
Response.Write(" <br/>Color:" +ShumaCar.Color);
Response.Write(" <br/>New gear:"+ShumaCar.Gear);
ShumaCar.ChangeGear("Up");
Response.Write(" <br/> <b>Shifted 'up' one gear. </b>");
Response.Write(" <br/>New gear:"+ShumaCar.Gear);
Response.Write(" <hr>Attempting to start ShumaCar with AlexEngine:");
ShumaCar.MyEngine("Ferrari", "050", "V10");
Response.Write(ShumaCar.MyEngine.SwitchOn);
Response.Write(" <hr>Attempting to start ShumaCar with RobEngine:");
ShumaCar.MyEngine(RobEngine);
Response.Write(ShumaCar.MyEngine.SwitchOn);
Response.Write(" <hr>Attempting to start ShumaCar with MyEngine:");
ShumaCar.MyEngine(MyEngine);
Response.Write(ShumaCar.MyEngine.SwitchOn);
Response.Write(" <br/>Attempting to stop ShumaCar:");
}</script>
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。编译器错误消息: CS0117: “ASP.aspnet_engine_object_aspx.Car”并不包含“MyEngine”的定义源错误:行 112: Engine MyEngine=new Engine("Xeer", "070","V6");
行 113:
行 114: AlexEngine=ShumaCar.MyEngine.Name;
行 115: RobEngine=ShumaCar.MyEngine.Name;
行 116: MyEngine=ShumaCar.MyEngine.Name;
修改以后还是不行啊,这个代码应该怎么改???<%@page language="C#" runat="server" Debug="true"%>
<script runat="server">
public class Engine
{
private string name;
private string rpm;
private string serialno;
public Engine(string Name, string Rpm, string SerialNo)//如果这里有参数名称,那么实例化一个engine的时候也要在括号内表明参数名称(并非参数)
{
name=Name;
rpm=Rpm;
serialno=SerialNo;
} public void SwitchOn()
{
if(Name=="Xeer" && Rpm=="070" && SerialNo=="V6")
{
return "The engine is running.";
}
else
{
return "The engine is not running.";
} }
}
public class Car
{
private string color;
private int gear;
private int ignition;
private Engine engine; public Engine objEngine
{
get
{
return engine;
}
set
{
engine=value;
}
}
public static int Count
{
get
{
return count;
}
}
public string Color
{
get
{
return color;
}
set
{
color=value;
}
}
public int Gear
{
get
{
return gear;
}
}
public void ChangeGear(int direction)
{
if(direction <0)gear-=1;
if(direction>0)gear+=1;
if(gear>5)gear=5;
if(gear <-1)gear=-1;
}
public void ChangeGear(string direction)
{
if(direction.ToLower()=="down")
{
ChangeGear(-1);
}
if(direction.ToLower()=="up")
{
ChangeGear(+1);
}
}
}
public void Page_Load()
{
Car ShumaCar=new Car();
ShumaCar.objEngine=new Engine("Xeer", "070","V6"); Engine AlexEngine=new Engine("Ferrari", "050", "V10");
Engine RobEngine=new Engine("Fdd", "060", "V3");
Engine MyEngine=new Engine("Xeer", "070","V6");
AlexEngine=ShumaCar.MyEngine.Name;
RobEngine=ShumaCar.MyEngine.Name;
MyEngine=ShumaCar.MyEngine.Name;
Response.Write(" <b>New object 'ShumaCar' created. </b>");
Response.Write(" <br/>Color:"+ShumaCar.Color);
Response.Write(" <br/>Gear:" +ShumaCar.Gear);
ShumaCar.Color="Black";
ShumaCar.ChangeGear(+1);
Response.Write(" <br/> <b>Properties updated. </b>");
Response.Write(" <br/>Color:" +ShumaCar.Color);
Response.Write(" <br/>New gear:"+ShumaCar.Gear);
ShumaCar.Color="Black";
ShumaCar.ChangeGear(+1);
Response.Write(" <br/> <b>Properties updated. </b>");
Response.Write(" <br/>Color:" +ShumaCar.Color);
Response.Write(" <br/>New gear:"+ShumaCar.Gear);
ShumaCar.ChangeGear("Up");
Response.Write(" <br/> <b>Shifted 'up' one gear. </b>");
Response.Write(" <br/>New gear:"+ShumaCar.Gear);
Response.Write(" <hr>Attempting to start ShumaCar with AlexEngine:");
ShumaCar.MyEngine("Ferrari", "050", "V10");
Response.Write(ShumaCar.MyEngine.SwitchOn);
Response.Write(" <hr>Attempting to start ShumaCar with RobEngine:");
ShumaCar.MyEngine(RobEngine);
Response.Write(ShumaCar.MyEngine.SwitchOn);
Response.Write(" <hr>Attempting to start ShumaCar with MyEngine:");
ShumaCar.MyEngine(MyEngine);
Response.Write(ShumaCar.MyEngine.SwitchOn);
Response.Write(" <br/>Attempting to stop ShumaCar:");
}</script>
RobEngine=ShumaCar.MyEngine.Name;
MyEngine=ShumaCar.MyEngine.Name;
改为
ShumaCar.objEngine.Name;
c:\inetpub\wwwroot\ASPNET\engine_object.aspx(147,20): error CS1503: 参数“1”: 无法从“void”转换为“string”
c:\inetpub\wwwroot\ASPNET\engine_object.aspx(151,29): error CS0119: “ASP.aspnet_engine_object_aspx.Car.MyEngine()”是一个“方法”,这在给定的上下文中无效
c:\inetpub\wwwroot\ASPNET\engine_object.aspx(155,29): error CS0119: “ASP.aspnet_engine_object_aspx.Car.MyEngine()”是一个“方法”,这在给定的上下文中无效
c:\inetpub\wwwroot\ASPNET\engine_object.aspx(21,9): error CS0127: 由于“ASP.aspnet_engine_object_aspx.Engine.SwitchOn(string, string, string)”返回 void,返回关键字后面不得有对象表达式
c:\inetpub\wwwroot\ASPNET\engine_object.aspx(25,9): error CS0127: 由于“ASP.aspnet_engine_object_aspx.Engine.SwitchOn(string, string, string)”返回 void,返回关键字后面不得有对象表达式
c:\inetpub\wwwroot\ASPNET\engine_object.aspx(29,9): error CS0127: 由于“ASP.aspnet_engine_object_aspx.Engine.SwitchOn(string, string, string)”返回 void,返回关键字后面不得有对象表达式
c:\inetpub\wwwroot\ASPNET\engine_object.aspx(53,11): error CS1002: 应输入 ;
c:\inetpub\wwwroot\ASPNET\engine_object.aspx(64,18): error CS0103: 当前上下文中不存在名称“count”帮忙啊,高手呢??
<%@page language="C#" runat="server" Debug="true"%>
<script runat="server">
public class Engine
{
private string name;
private string rpm;
private string serialno;
private string Name2;
public Engine(string Name, string Rpm, string SerialNo)//如果这里有参数名称,那么实例化一个engine的时候也要在括号内表明参数名称(并非参数)
{
name=Name;
rpm=Rpm;
serialno=SerialNo;
} public void SwitchOn(string Name, string Rpm, string SerialNo)
{
if(Name=="Xeer" && Rpm=="070" && SerialNo=="V6")
{
return "The engine is running.";
}
else if(Name=="Ferrari" && Rpm=="050" && SerialNo=="V10")
{
return "The engine is not running.";
}
else if(Name=="Fdd" && Rpm=="060" && SerialNo=="V3")
{
return "The engine is not running.";
}
}
}
public class Car
{
private string color;
private int gear;
private int ignition;
private Engine engine; public Engine objEngine
{
get
{
return engine;
}
set
{
engine=value;
}
}
public void MyEngine()
{
get
{
return engine;
}
}
public static int Count
{
get
{
return count;
}
}
public string Color
{
get
{
return color;
}
set
{
color=value;
}
}
public int Gear
{
get
{
return gear;
}
}
public void ChangeGear(int direction)
{
if(direction <0)gear-=1;
if(direction>0)gear+=1;
if(gear>5)gear=5;
if(gear <-1)gear=-1;
}
public void ChangeGear(string direction)
{
if(direction.ToLower()=="down")
{
ChangeGear(-1);
}
if(direction.ToLower()=="up")
{
ChangeGear(+1);
}
}
}
public void Page_Load()
{
Car ShumaCar=new Car();
Engine AlexEngine=new Engine("Ferrari", "050", "V10");
Engine RobEngine=new Engine("Fdd", "060", "V3");
Engine MyEngine=new Engine("Xeer", "070", "V6");
ShumaCar.objEngine=new Engine("Xeer", "070","V6"); Response.Write(" <b>New object 'ShumaCar' created. </b>");
Response.Write(" <br/>Color:"+ShumaCar.Color);
Response.Write(" <br/>Gear:" +ShumaCar.Gear);
ShumaCar.Color="Black";
ShumaCar.ChangeGear(+1);
Response.Write(" <br/> <b>Properties updated. </b>");
Response.Write(" <br/>Color:" +ShumaCar.Color);
Response.Write(" <br/>New gear:"+ShumaCar.Gear);
ShumaCar.Color="Black";
ShumaCar.ChangeGear(+1);
Response.Write(" <br/> <b>Properties updated. </b>");
Response.Write(" <br/>Color:" +ShumaCar.Color);
Response.Write(" <br/>New gear:"+ShumaCar.Gear);
ShumaCar.ChangeGear("Up");
Response.Write(" <br/> <b>Shifted 'up' one gear. </b>");
Response.Write(" <br/>New gear:"+ShumaCar.Gear);
Response.Write(" <hr>Attempting to start ShumaCar with AlexEngine:"); Response.Write(ShumaCar.objEngine.SwitchOn("Ferrari", "050", "V10"));
Response.Write(" <hr>Attempting to start ShumaCar with RobEngine:");
ShumaCar.objEngine=new Engine("Fdd", "060", "V3");
Response.Write(ShumaCar.MyEngine.SwitchOn);
Response.Write(" <hr>Attempting to start ShumaCar with MyEngine:");
ShumaCar.objEngine=new Engine("Xeer", "070", "V6");
Response.Write(ShumaCar.MyEngine.SwitchOn);
Response.Write(" <br/>Attempting to stop ShumaCar:");
}</script>