Classes and properties
โ Report an issue with this lessonpublic 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.
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