C#错误:';对象';不包含';财产';没有扩展方法';财产';

C#错误:';对象';不包含';财产';没有扩展方法';财产';,c#,properties,C#,Properties,我在此程序中使用的每个属性实例都会出现此错误: “对象”不包含“属性”的定义,也没有扩展名 接受类型为“object”的第一个参数的方法“Property”可以是 找到了 我做错了什么 using System; using System.Collections; using static System.Console; namespace CalculateGrossPay { public class CalculateGrossPay { static ArrayList emp

我在此程序中使用的每个属性实例都会出现此错误:

“对象”不包含“属性”的定义,也没有扩展名 接受类型为“object”的第一个参数的方法“Property”可以是 找到了

我做错了什么

using System;
using System.Collections;
using static System.Console;

namespace CalculateGrossPay
{
public class CalculateGrossPay
{
    static ArrayList employees = new ArrayList();
    static int numOfEmployees = 0;

    static void main()
    {
        PrintMenu();
    }

    public static void PrintMenu()
    {
        string name;
        double annualSalary;
        double monthlySales;
        string input;

        WriteLine("Enter employee's name (enter nothing to quit): ");
        name = ReadLine();
        while (name != "")
        {
            WriteLine("Enter Annual Salary (0 for pure commission): ");
            input = ReadLine();
            annualSalary = double.Parse(input);
            WriteLine("Enter Monthly Sales: ");
            input = ReadLine();
            monthlySales = double.Parse(input);

            AddEmployee(name, GetBasePay(annualSalary), monthlySales);

            ReportPay();

            WriteLine("\nEnter employee's name (enter nothing to quit): ");
            name = ReadLine();
        }
    }

    public static double GetBasePay(double annualSalary)
    {
        return annualSalary / 12;
    }

    public static void AddEmployee(string name, double basePay, double monthlySales)
    {
        Employee employee = new Employee(name, basePay, monthlySales);
        employees.Add(employee);
        numOfEmployees++;
    }

    public static void ReportPay()
    {
        WriteLine(employees[numOfEmployees - 1].Name);
        WriteLine("Base Salary: {C:2}", employees[numOfEmployees - 1].BasePay);
        WriteLine("Sales: {C:2}", employees[numOfEmployees - 1].Sales);
        WriteLine("Commission: {C:2}", employees[numOfEmployees - 1].ReturnCommission(employees[numOfEmployees - 1].BasePay,
                            employees[numOfEmployees - 1].Sales));


        WriteLine("Gross Pay: {C:2}", employees[numOfEmployees - 1].ReturnGrossPay(employees[numOfEmployees - 1].BasePay, 
                            employees[numOfEmployees - 1].Sales));
    }

}

public class Employee {
    private string name;
    private double basePay;
    private double sales;

    public string Name
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }

    public double BasePay
    {
        get
        {
            return basePay;
        }
        set
        {
            basePay = value;
        }
    }

    public double Sales
    {
        get
        {
            return sales;
        }
        set
        {
            sales = value;
        }
    }

    public Employee(string nameOfEmployee)
    {
        name = nameOfEmployee;
    }

    public Employee(string nameOfEmployee, double pay, double monthlySales)
    {
        name = nameOfEmployee;
        basePay = pay;
        sales = monthlySales;
    }

    public double ReturnCommission(double basePay, double monthlySales)
    {
        double netSales = monthlySales - (10 * basePay);

        double commission = 0;

        if (netSales <= 0)
        {
            commission = 0;
        }
        else if (netSales > 50000)
        {
            commission = (netSales - 50000) * .2;
            commission += 25000 * .15;
            commission += 15000 * .1;
            commission += 10000 * .05;
        }
        else if (netSales > 25000)
        {
            commission = (netSales - 25000) * .15;
            commission += 15000 * .1;
            commission += 10000 * .05;
        }
        else if (netSales > 10000)
        {
            commission = (netSales - 10000) * .1;
            commission += 10000 * .05;
        }

        return commission;
    }

    public double ReturnGrossPay(double basePay, double monthlySales)
    {
        return basePay + ReturnCommission(basePay, monthlySales);
    }
}
}
使用系统;
使用系统集合;
使用静态系统控制台;
命名空间CalculateGrossPay
{
公共类计算工资
{
静态ArrayList employees=新ArrayList();
静态int numOfEmployees=0;
静态void main()
{
打印菜单();
}
公共静态无效打印菜单()
{
字符串名;
双年轮;
双月季;
字符串输入;
WriteLine(“输入员工姓名(不输入要退出的内容):”;
name=ReadLine();
而(名称!=“”)
{
WriteLine(“输入年薪(纯佣金为0):”;
输入=读线();
annualSalary=double.Parse(输入);
WriteLine(“输入月度销售额:”);
输入=读线();
monthlySales=double.Parse(输入);
新增员工(姓名、基本工资(年薪)、月工资);
ReportPay();
WriteLine(“\n输入员工姓名(不输入要退出的内容):”;
name=ReadLine();
}
}
公共静态双倍基本工资(双倍年薪)
{
返回年度日历/12;
}
public static void AddEmployee(字符串名称、双基薪、双月工资)
{
员工=新员工(姓名、基本工资、月销售额);
employees.Add(employees);
NUMOF++;
}
公共静态无效报告支付()
{
WriteLine(employees[numOfEmployees-1].Name);
WriteLine(“基本工资:{C:2}”,雇员[numOfEmployees-1]。基本工资);
WriteLine(“销售:{C:2}”,雇员[numOfEmployees-1]。销售);
WriteLine(“佣金:{C:2}”,雇员[numOfEmployees-1]。退货佣金(雇员[numOfEmployees-1]。基本工资,
员工[numOfEmployees-1].销售];
WriteLine(“工资总额:{C:2}”,雇员[numOfEmployees-1]。ReturnGrossPay(雇员[numOfEmployees-1]。基本工资,
员工[numOfEmployees-1].销售];
}
}
公营雇员{
私有字符串名称;
私人双底薪;
私人双重销售;
公共字符串名
{
得到
{
返回名称;
}
设置
{
名称=值;
}
}
公共双底薪
{
得到
{
返回基本工资;
}
设置
{
基本工资=价值;
}
}
公开双重销售
{
得到
{
退货;
}
设置
{
销售额=价值;
}
}
公共雇员(雇员的字符串名称)
{
姓名=员工姓名;
}
公共雇员(雇员的字符串名称、双薪、双月工资)
{
姓名=员工姓名;
基本工资=工资;
销售额=月销售额;
}
公共双薪委员会(双基薪、双月工资)
{
双倍净销售额=月销售额-(10*基本工资);
双重佣金=0;
if(净销售额50000)
{
佣金=(净销售额-50000)*.2;
佣金+=25000*.15;
佣金+=15000*.1;
佣金+=10000*.05;
}
否则如果(净销售额>25000)
{
佣金=(净销售额-25000)*.15;
佣金+=15000*.1;
佣金+=10000*.05;
}
否则,如果(净销售额>10000)
{
佣金=(净销售额-10000)*.1;
佣金+=10000*.05;
}
退货佣金;
}
公共双倍工资(双倍基本工资,双月工资)
{
返回基本工资+返回佣金(基本工资,每月销售);
}
}
}
问题在于将对象作为
对象包含。
我建议使用
List
而不是
ArrayList

发件人:

对于ArayLead的强类型替代,考虑使用List.ArayLead可能并不总是为给定任务提供最佳性能。请参阅列表引用主题中的“性能考虑”部分,讨论这些类的相对性能。

换衣服

    static ArrayList employees = new ArrayList();

static List employees=new List();
问题在于将对象作为
对象包含。
我建议使用
List
而不是
ArrayList

发件人:

对于ArayLead的强类型替代,考虑使用List.ArayLead可能并不总是为给定任务提供最佳性能。请参阅列表引用主题中的“性能考虑”部分,讨论这些类的相对性能。

换衣服

    static ArrayList employees = new ArrayList();

static List employees=new List();

完美。这就解决了问题。谢谢如果你不介意再看一眼的话,我还有一个问题。为什么它会给我错误“程序不包含适合入口点的静态“Main”方法”@JimboSakahana任何程序都应该有
Main
方法,并且区分大小写。将
main
更改为
main
,我还将“main”中的“m”大写,但它仍然给了我错误。@JimboSakahana
static void main()
?是的,这就是我现在所拥有的。但是错误并没有消失。完美。这就解决了问题。谢谢如果你不介意再看一眼的话,我还有一个问题。为什么它会给我错误“程序不包含适合入口点的静态“Main”方法”@JimboSakahana任何程序都应该有
Main
方法,并且它是ca