Object-Oriented C# · Lesson 2

Classes

A class stores values and offers a method that reads them.

How it works

Invoice keeps an id and an amount that the constructor stored. Label reads those fields from the object you call it on and joins them. This call prints a 12. A second Invoice would keep its own id and amount. The method does not look at a different object.

A working example

var invoice = new Invoice("a", 12);
Console.WriteLine(invoice.Label());

class Invoice
{
    public string Id { get; }
    public int Amount { get; }

    public Invoice(string id, int amount)
    {
        Id = id;
        Amount = amount;
    }

    public string Label() => Id + " " + Amount;
}

Try this
Construct the object, then call Label on that object.