Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Read-Only Collection Interface

Challenge Task 1 of 1

Change the type of the Entries property to return a read-only collection such that the client of the FitnessRecord class can still index into the collection but can’t add or remove anything from it.

1 Answer

Umesh Ravji
Umesh Ravji
42,386 Points

Hi Maggie, this can be achieved by changing the return type too.

System.Collections.Generic.IReadOnlyList<ActivityEntry> 
Brody Ricketts
Brody Ricketts
15,612 Points

This is not the proper way of using the IReadOnlyList collection as we are already using System.Collections.Generic for this code challenge. This implementation breaks the DRY(Do not Repeat Yourself) rule. This will also be corrected in Visual Studio using the Ctrl + . shortcut key. When dealing with this code challenge, simply changing the list to a readonly collection as stated by Umesh will satisfy the requirements. Please see the Microsoft doc on collections to better understand this. https://msdn.microsoft.com/en-us/library/hh192385(v=vs.110).aspx