这部分代码在整个程序中如何被调用?

changeking 2009-01-17 12:08:40
private static int count=0;

public static int Count
{
get
{
return count;
}
}
上面这部分代码在整个程序中如何被调用阿?
下面是代码
--------------------------------------------------------------------------------------------------------------------

<%@page language="C#" runat="server" Debug="true"%>
<script runat="server">
public class Key
{
private int shape;
public Key(int newshape)
{
shape=newshape;
}

public int Shape
{
get
{
return shape;
}
}
}
public class Car
{
private string color;
private int gear;
private int ignition;
private bool engineRunning;
private static int count=0;


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 Car(int IgnitionShape)
{
color="Cold gray steel";
ignition=IgnitionShape;
count+=1;
}


public void Ignition(Key IgnitionKey)

{
if(IgnitionKey.Shape==ignition)
engineRunning=true;
else
engineRunning=false;
}

public void EngineOff()
{
engineRunning=false;
}


public string IsRunning
{
get
{
if(engineRunning)
{
return "The engine is running.";
}
else
{
return "The engine is not running.";
}
}
}
}
public void Page_Load()
{
Key AlexKey=new Key(0987654321);
Key RobKey=new Key(1861005040);
Key MyKey=new Key(1234567890);

Car MyCar=new Car(1234567890);
Response.Write("<b>New object 'MyCar' created.</b>");

Response.Write("<br/>Color:"+MyCar.Color);
Response.Write("<br/>Gear:" +MyCar.Gear);

MyCar.Color="Black";
MyCar.ChangeGear(+1);
Response.Write("<br/><b>Properties updated.</b>");

Response.Write("<br/>Color:" +MyCar.Color);
Response.Write("<br/>New gear:"+MyCar.Gear);//car对象调用的是Gear这个方法,但是在这个方法里没有count,那请问这个count是如何通过//调用Gear这个方法实现的?他们是怎么联系上的?

MyCar.Color="Black";
MyCar.ChangeGear(+1);
Response.Write("<br/><b>Properties updated.</b>");

Response.Write("<br/>Color:" +MyCar.Color);
Response.Write("<br/>New gear:"+MyCar.Gear);

MyCar.ChangeGear("Up");
Response.Write("<br/><b>Shifted 'up' one gear.</b>");
Response.Write("<br/>New gear:"+MyCar.Gear);




Response.Write("<hr>Attempting to start MyCar with AlexKey:");
MyCar.Ignition(AlexKey);
Response.Write(MyCar.IsRunning);

Response.Write("<hr>Attempting to start MyCar with RobKey:");
MyCar.Ignition(RobKey);
Response.Write(MyCar.IsRunning);

Response.Write("<hr>Attempting to start MyCar with MyKey:");
MyCar.Ignition(MyKey);
Response.Write(MyCar.IsRunning);
Response.Write("<br/>Attempting to stop MyCar:");


MyCar.EngineOff();
Response.Write(MyCar.IsRunning);


}
</script>
...全文
82 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
net_xiaojian 2009-01-17
  • 打赏
  • 举报
回复
ls的不懂瞎说,也上排名的时候他分没你多,后来几天他挣得分比你多,下期排名就超过你了.
arjsyy 2009-01-17
  • 打赏
  • 举报
回复
1楼正解
winner2050 2009-01-17
  • 打赏
  • 举报
回复
-_-! 楼上技术分比我多,但是排名比我低!!

jiang_jiajia10 2009-01-17
  • 打赏
  • 举报
回复
静态方法通过类名就可以访问呀
changeking 2009-01-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jiang_jiajia10 的回复:]
静态方法通过类名就可以访问呀
[/Quote]
谢谢大家,长见识了
supremeholy 2009-01-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jiang_jiajia10 的回复:]
静态方法通过类名就可以访问呀
[/Quote]
up!
别样苍茫 2009-01-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jiang_jiajia10 的回复:]
静态方法通过类名就可以访问呀
[/Quote]UP

62,269

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧