我是C#的新手,對我來說真的很困難。我正在用C#編寫這個程序,這是我面臨的錯誤。不包含此內容的定義
錯誤1「Lab1.Invoice」不包含關於「部分號碼」和沒有擴展方法「部分號碼」接受類型「Lab1.Invoice」的第一個參數的定義可以找到(是否缺少using指令?集引用)
這裏是我的代碼:
using System;
namespace Lab1
{
class InvoiceTest
{
static void Main(string[] args)
{
string partNumber, partDescription;
int quantity;
decimal Iprice;
Console.WriteLine("Part Number:");
partNumber = Console.ReadLine();
Console.WriteLine("Part Description:");
partDescription = Console.ReadLine();
Console.WriteLine("Quantity:");
quantity = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Price:");
Iprice = Convert.ToDecimal(Console.ReadLine());
Invoice invoice = new Invoice(partNumber, partDescription, quantity, Iprice);
Console.WriteLine("Order: ");
Console.WriteLine("Part Number: {0}", invoice.partNumber);
Console.WriteLine("Description: {0}", invoice.pDescription);
Console.WriteLine("Quantity: {0}", invoice.Quantity);
Console.WriteLine("Price: {0}", invoice.Price);
Console.WriteLine("Total: {0}", invoice.GetInvoiceAmount());
}
}
}
Here is the code for Invoice:<br>
namespace Lab1
{
class Invoice
{
private int qty;
private decimal price;
private string pNumber { get; set; }
private string pDescription { get; set; }
public Invoice(string partNumber, string partDescription, int quantity, decimal Iprice)
{
pNumber = partNumber;
pDescription = partDescription;
Quantity = quantity;
Price = Iprice;
}
public int Quantity
{
get
{
return qty;
}
set
{
if (value > 0)
qty = value;
else
qty = 1;
}
}
public decimal Price
{
get
{
return price;
}
set
{
if (value > 0)
price = value;
else
price = 1;
}
}
public decimal GetInvoiceAmount()
{
return Quantity * Price;
}
}
}
該錯誤是非常具有描述性的。 「發票」的定義在哪裏? –
您在「發票」類的定義中是否有一個名爲partNumber的屬性? – Dido
其在另一個班級內創建的公共班級 – hades