C# object.object的最佳重载匹配具有一些无效参数

C# object.object的最佳重载匹配具有一些无效参数,c#,class,object,properties,C#,Class,Object,Properties,我正在尝试创建发票类型的新对象。我以正确的顺序传递必要的参数 然而,它告诉我,我包含了无效的参数。我可能忽略了一些非常简单的事情,但也许有人可以指出 我正在做作业,但是Invoice.cs文件包含在项目中使用 我寻求的唯一解决方案是为什么我的对象不接受这些值。我以前从未遇到过对象的问题 以下是我的代码: static void Main(string[] args) { Invoice myInvoice = new Invoice(83, "Electric sander", 7, 5

我正在尝试创建发票类型的新对象。我以正确的顺序传递必要的参数

然而,它告诉我,我包含了无效的参数。我可能忽略了一些非常简单的事情,但也许有人可以指出

我正在做作业,但是Invoice.cs文件包含在项目中使用

我寻求的唯一解决方案是为什么我的对象不接受这些值。我以前从未遇到过对象的问题

以下是我的代码:

static void Main(string[] args)
{
    Invoice myInvoice = new Invoice(83, "Electric sander", 7, 57.98);
}
这是实际的Invoice.cs文件:

// Exercise 9.3 Solution: Invoice.cs
// Invoice class.
public class Invoice
{
   // declare variables for Invoice object
   private int quantityValue;
   private decimal priceValue;

   // auto-implemented property PartNumber
   public int PartNumber { get; set; }

   // auto-implemented property PartDescription
   public string PartDescription { get; set; }

   // four-argument constructor
   public Invoice( int part, string description,
      int count, decimal pricePerItem )
   {
      PartNumber = part;
      PartDescription = description;
      Quantity = count;
      Price = pricePerItem;
   } // end constructor

   // property for quantityValue; ensures value is positive
   public int Quantity
   {
      get
      {
         return quantityValue;
      } // end get
      set
      {
         if ( value > 0 ) // determine whether quantity is positive
            quantityValue = value; // valid quantity assigned
      } // end set
   } // end property Quantity

   // property for pricePerItemValue; ensures value is positive
   public decimal Price
   {
      get
      {
         return priceValue;
      } // end get
      set
      {
         if ( value >= 0M ) // determine whether price is non-negative
            priceValue = value; // valid price assigned
      } // end set
   } // end property Price

   // return string containing the fields in the Invoice in a nice format
   public override string ToString()
   {
      // left justify each field, and give large enough spaces so
      // all the columns line up
      return string.Format( "{0,-5} {1,-20} {2,-5} {3,6:C}",
         PartNumber, PartDescription, Quantity, Price );
   } // end method ToString
} // end class Invoice

您的方法需要一个
decimal
参数,其中当您传递一个
double
值(57.98)时

根据(见备注部分)

浮点类型和 十进制类型

对于小数,应添加后缀“m”或“m”

因此,在你的情况下,通过57.98米而不是57.98米

列出各种后缀


您的方法需要一个
decimal
参数,其中当您传递一个
double
值(57.98)时

根据(见备注部分)

浮点类型和 十进制类型

对于小数,应添加后缀“m”或“m”

因此,在你的情况下,通过57.98米而不是57.98米

列出各种后缀


试着在57.98后面加一个“M”。事实上,这个数字是一个双常数,我相信它不能转换成十进制,但57.98M是一个十进制常数。试着在57.98后面加一个“M”。事实上,这个数字是一个双常数,我相信它不能转换成十进制,但57.98M是一个十进制常数。啊。非常感谢。我应该停止熬夜这么晚!啊。非常感谢。我应该停止熬夜这么晚!