为什么我在这个 C# 程序上收到“当前上下文中不存在该名称”错误?
这是我的类文件:
namespace Exercise8
{
class Park
{
Park aPark = new Park();
private string name;
public string Name
{
get
{
name = Console.ReadLine();
return name;
}
set
{
}
}
private string location;
public string Location
{
get
{
location = Console.ReadLine();
return location;
}
set
{
}
}
private string facilityType;
public string FacilityType
{
get
{
facilityType = Console.ReadLine();
return facilityType;
}
set
{
}
}
private string facilitiesAvailable;
public string FacilitiesAvailable
{
get
{
facilitiesAvailable = Console.ReadLine();
return facilitiesAvailable;
}
set
{
}
}
private double fee;
public string sFee;
public double Fee
{
get
{
fee = double.Parse(sFee);
sFee = Console.ReadLine();
return fee;
}
set
{
}
}
private int noOfEmployees;
public string sNoOfEmployees;
public int NoOfEmployees
{
get
{
noOfEmployees = int.Parse(sNoOfEmployees);
sNoOfEmployees = Console.ReadLine();
return noOfEmployees;
}
set
{
}
}
//variables for Cost Per Visitor.
//noVisitors will be used in Calculate Revenue
public double costPerVisitor;
public double annualBudget = 200000;
public double noVisitors = 10000;
public double CalculateCostPerVisitor(double annualBudget, double noOfVisitors)
{
//divide annual budget by number of visitors
return costPerVisitor = annualBudget / noVisitors;
}
//Calculate Revenue
public double revenue;
public double CalculateRevenue(double noOfVisitors,double fee)
{
//No of Visitors times Fee
revenue = noVisitors * fee;
return revenue;
}
public override string ToString()
{
return "Name of park: " + this.Name + "\nLocation: " + this.Location + "\nFacility Type: " + this.FacilityType + "\nFacility Fee: " + this.Fee + "\nNumber of employees: " + this.NoOfEmployees +
"\nNumber of visitors recorded in the past 12 months: " + this.noVisitors + "Annual Budget: " + this.annualBudget;
}
}
}
这是我的程序:
namespace Exercise8
{
class Program
{
public static void main (String [] args)
{
//Instantiate Objects
Park aPark = new Park();
//Call Methods
Console.WriteLine("Name of park: " + aPark.Name + "; Location of park: " + aPark.Location + "; Type of park: " + aPark.FacilityType);
Console.WriteLine("Name of park: " + aPark.Name + "; Location of park: " + aPark.Location + "; Facilities available: " + aPark.FacilitiesAvailable);
Console.WriteLine("Annual cost per visitor: " + CalculateCostPerVisitor());
Console.WriteLine("Revenue: " + CalculateRevenue());
//Below should hopefully return To String
Console.WriteLine(aPark.ToString());
}
}
}
这些是我看到的错误:
当前上下文中不存在名称“CalculateCostPerVisitor”
当前上下文行中不存在名称“CalculateRevenue”