标题:[新手学习]书上的代码 -----有点问题--请教
只看楼主
mynet
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-4-21
 问题点数:0 回复次数:2 
[新手学习]书上的代码 -----有点问题--请教

//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
从小到大
Rank: 1
等 级:新手上路
威 望:2
帖 子:200
专家分:0
注 册:2006-6-24
得分:0 
Personger personger = new Person();

2007-04-27 23:00
天使不哭
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:677
专家分:22
注 册:2006-7-9
得分:0 
public void LoadPasseager
{
Passenger = new Person();

}


没有看明白这是什么,方法不象方法,
属性吧,缺少get和set
不明白 ~~~~


C#Winform技术群:25380362
博客:http:///boyliupan/
2007-04-28 11:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-135475-1-1.html




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

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