| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 581 人关注过本帖
标题:[新手学习]书上的代码 -----有点问题--请教
取消只看楼主 加入收藏
mynet
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-4-21
收藏
 问题点数:0 回复次数:0 
[新手学习]书上的代码 -----有点问题--请教

//A simlpe elevator simulation
using System;
class Elevator
{
private int currentFloor = 1;
private int requestedFloor = 0;
private int totalFloorsTraveled = 0;

private Person passenger;

public void LoadPasseager
{
Passenger = new Person();

}

public void InitiateNewFloorRequest()
{
requestedFloor = passenger.NewFloorRequest();
Console.WriteLine("Departing floor:" + currentFloor + "Traveling to floor:" + requestedFloor);
totalFloorsTraveled = totalFloorsTraveled + Math.Abs(currentFloor + requestedFloor);
currentFloor = requestedFloor;
}
public void ReportStatistic()
{
Console.WriteLine("Total floors traveled:" + totalFloorsTraveled);
}
}
class Person
{
private System.Random randomNumbergenerator;

public Person()
{
randomNumbergenerator = new System.Random();
}

public int NewFloorRequst()
{
//Return randonly generated number
return randomNumbergenerator.Next(1,30);
}

}
class Building
{
private static Elevator elevatorA;

public static void Main()
{
elevatorA = new Elevator();
elevatorA.LoadPasseager();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.InitiateNewFloorRequest();
elevatorA.ReportStatistic();

}
}

红色部分的 Personger = new Person();出现错误 错误为:应为get 或 set访问器.
如何解决这个错误

我是刚刚学C#~~以后还要大家多多指教.

[此贴子已经被作者于2007-4-27 23:56:31编辑过]

搜索更多相关主题的帖子: private int passenger 代码 
2007-04-27 19:24
快速回复:[新手学习]书上的代码 -----有点问题--请教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016420 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved