root@coding-prodigies:~# โ–Š
// lesson 3 of 11 ยท 18 min

Classes and properties

โš‘ Report an issue with this lesson
public class Course
{
    public string Title { get; set; }
    public double Price { get; private set; }

    public Course(string title, double price)
    {
        Title = title;
        Price = price;
    }

    public string Describe() => $"{Title} -- ${Price}";
}

{ get; set; } auto-properties save you from writing manual getter/setter methods for simple fields, while private set keeps Price only settable from inside the class.

Try it yourself

Exercise: Add a Describe() method to Course using its auto-properties.
Expected output: open-ended โ€” there's no single correct output here, just get your code running without errors.
csharp
Output

      
    

Run your code and get it working before marking this lesson complete.

// that was the last free lesson

8 more lessons โ€” including Capstone project: a course catalog console app โ€” plus a certificate are waiting.

Unlock the full course โ€” $149.99