【发布时间】:2012-06-11 12:09:39
【问题描述】:
嘿,我是 C# 新手,我正在学习一个教程,但我的代码中出现错误...它在到达此处 (get;set;) 时显示“预期标识符”,并且还给出错误“无效令牌';'在类、结构或接口成员声明中”在集合中。
任何帮助都将不胜感激。
谢谢!!
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);
}
}
【问题讨论】:
标签: c# identifier