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# C# Collections Lists Read-only Collection Interfaces

help 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.

FitnessRecord.cs
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; } }
    }
}
ActivityEntry.cs
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

For Entries you need to use a list of type IReadOnlyList. I'll leave the implementation up to you because it should be simple enough.

thank you very much it worked

Noah Yasskin
Noah Yasskin
23,946 Points
using System.Collections.Generic;

namespace Treehouse.CodeChallenges
{
    public class FitnessRecord
    {
        private List<ActivityEntry> _entries = new List<ActivityEntry>();

        public IReadOnlyList<ActivityEntry> Entries { get { return _entries; } }
    }
}