嘿,我是新來的C#和我正在跟隨一個教程,但我在我的代碼中得到一個錯誤...它說:「標識符預期」在這裏(get; set;),也給出了錯誤「令牌無效';'在類,結構或接口成員聲明「中。標識符預計c#
任何幫助都將不勝感激。
謝謝!
public class Invoice
{
public int ID (get; set;)
public string Description (get; set;)
public decimal Amount (get; set;)
}
[TestClass]
public class ReferenceTypesAndValueTypes
{
[TestMethod]
public void IdentityTest()
{
Invoice firstInvoice = new Invoice();
firstInvoice.ID = 1;
firstInvoice.Description = "Test";
firstInvoice.Amount = 0.0M;
Invoice secondInvoice = new Invoice();
secondInvoice.ID = 1;
secondInvoice.Description = "Test";
secondInvoice.Amount = 0.0M;
Assert.IsFalse(object.ReferenceEquals(secondInvoice, firstInvoice));
Assert.IsTrue(firstInvoice.ID == 1);
secondInvoice.ID = 2;
Assert.IsTrue(secondInvoice.ID == 2);
Assert.IsTrue(firstInvoice.ID == 1);
secondInvoice = firstInvoice;
Assert.IsTrue(object.ReferenceEquals(secondInvoice,firstInvoice));
secondInvoice.ID = 5;
Assert.IsTrue(firstInvoice.ID == 5);
}
}
大聲笑我剛剛評論與「哪裏」:P很高興你編輯 – rlemon
沒問題的傢伙。 – dtsg