日期:2014-05-18  浏览次数:20418 次

[新手]帮忙纠正这个涉及到对象的调用的代码
帮忙纠正这个代码,涉及到对象的调用,不会..>_<
<%@page language="C#" runat="server" Debug="true"%>
<script runat="server">


 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 Engine(string Name, int Rpm, string SerialNo)
  {
  name=Name;
  rpm=Rpm;
  serialno=SerialNo;
  }
   
  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 SwitchOn(string Name)
  {
  if(Name==JayEngine)
  {
  return "The engine is running.";
  }
  else
  {
  return "The engine is not running.";
  }
  
  }
  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");
   
  JayEngine=ShumaCar.MyEngine.Name;
  JayEngine=ShumaCar.MyEngine.SwitchOn();
   

  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);<