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 trialtafadzwa manzunzu
3,601 Pointshelp please
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.
using System.Collections.Generic;
namespace Treehouse.CodeChallenges
{
public class FitnessRecord
{
private List<ActivityEntry> _entries = new List<ActivityEntry>();
public Read-only<ActivityEntry> Entries { get { return _entries; } }
}
}
using System;
namespace Treehouse.CodeChallenges
{
public class ActivityEntry
{
public string Name { get; set; }
public DateTime Started { get; set; }
public DateTime Finished { get; set; }
}
}
2 Answers
emmuster
1,533 PointsFor Entries you need to use a list of type IReadOnlyList. I'll leave the implementation up to you because it should be simple enough.
Noah Yasskin
23,947 Pointsusing System.Collections.Generic;
namespace Treehouse.CodeChallenges
{
public class FitnessRecord
{
private List<ActivityEntry> _entries = new List<ActivityEntry>();
public IReadOnlyList<ActivityEntry> Entries { get { return _entries; } }
}
}
tafadzwa manzunzu
3,601 Pointstafadzwa manzunzu
3,601 Pointsthank you very much it worked