Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,945 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; } }
    }
}