Identifier expected c#

Hey I am new to C# and I am following a tutorial but I am getting an error in my code... It says "Identifier expected" at get here ( get; set; ) and also gives the error "Invalid token';' in class, struct, or interface member declaration" at set.

Any help at all would be greatly appreciated.

Thanks!!

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);

    }
}

Answers


You need to replace the brackets () with braces {}

E.g.

public class Invoice
{
    public int ID { get; set; }
    public string Description { get; set; }
    public decimal Amount { get; set; }
}

In auto properties, the syntactic sugar allows you to leave off the implementation of the getter/setter - so you should have this:

SomeProperty { get; set; } 

it's the equivalent of going:

SomeProperty 
{ 
   get { return _somePropertyBackingField; }
   set { _somePropertyBackingField = value; }
}

None of these require parenthesis, since this is structural notation - parenthesis are usually reserved for casting and method calls

 SomeProperty ( get; set; )

Doesn't mean much to the interpreter

You know there are code snippets in Visual Studio which can do this for you:

Just type "prop" and hit tab twice. Try it :) - no more typos


Need Your Help

Building GNU Make using MinGW - errors in build_w32.bat

windows batch-file gcc

The README document (for versions 3.81 and 4.1) directs running the command

Login Test - Laravel

php laravel

I'm new to laravel and was attempting to test a user login but since I've started using in memory sqlite I've been having problems. My Code: