c# - 从类中调用 double

标签 c#

你好,

我正在尝试从类“钱包”中调用双重支付 但是当我尝试这样做时,它给出了这个错误:

Member'Mc_DOnalds.Program.Paying' cannot be accessed with an instance reference; qualify it with a type name instead.   

这是在钱包类中。

class Wallet
{
    public double WalletCustomer = 100;

    Program Betalen = new Program();
    public void Pay()
    {
        WalletCustomer = (WalletCustomer - Betalen.Paying);            
    }
  }
}

这是在Program.cs中

 public static double Paying = 0;

最佳答案

因为 Paying 是静态的,您不需要创建类的实例来访问该属性。试试这个(看看我如何访问 Program.Paying):

class Wallet
{
    public double WalletCustomer = 100;

    public void Pay()
    {
        WalletCustomer = (WalletCustomer - Program.Paying);            
    }
  }
}

关于c# - 从类中调用 double ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22373396/

相关文章:

c# - 在 C# 中获取系统可空日期时间(日期时间?)的短日期

c# - 运行单元测试时更改 app.config

c# - 在 C# 中将 Task<T> 转换为 Task<object> 而无需 T

c# - Azure AD B2C 以编程方式获取 token 以进行单元测试

c# - 如何获取自定义用户控件内的所有文本框?

c# - 任务完成后如何调用方法?

c# - int 到 string 没有显式转换?

c# - 将日期时间字符串转换为原始时区的日期时间

c# - Enum.Parse 无法转换字符串

c# - 操作方法 : Validate a FileStream is a valid PDF document with . NET