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# Querying With LINQ Now You're Querying Object Initialization

Daniel Hunter
Daniel Hunter
4,622 Points

Technical Issues with challenge

CHALLENGE LINK: https://teamtreehouse.com/library/querying-with-linq/now-youre-querying/object-initialization-2

TASK DETAILS: Refactor the LoadBirds method by using object initialization to add the pelican to the birds variable. Code files attached.

ERROR MESSAGE: OH NO! we didn't hear from the challenge service in a timely fashion.

if you continue experiencing problems, please contact support at helpTeamtreehouse.com

(First time i contacted support they advised to try different browsers etc. I attempted the challenge on different browsers and then with add-ons disabled. The issue continued, I then contacted support again and got this reply:

Sometimes when this happens, it's due to an issue with the code itself, if those troubleshooting steps I outlined earlier did not resolve the issue.

Because our support team does not consist of teachers or developers, we are limited in what assistance we can provide. Instead, if you're stuck on this particular task, please create a post on our Community page and provide the following information within your post: ā€¢ Link us to the Code Challenge in question and verify which Task # it is. ā€¢ Post the code you're entering in (remember to use markdown to wrap your code for easy reading) or include a screenshot of your code within the Code Challenge itself, having it include the "Bummer!" message located at the top when it doesn't accept your answer. Once this is up on the Community page, give it some time for people to see it and respond. If a day has passed and you still haven't received the help you're looking for, send a link to your forum post via email to help@teamtreehouse.com. Thank you!)

CODE: Code files linked to post.

I found that when I make a deliberate mistake in the code (e.g. remove a curly brace), I get a compiler error (as you would expect), so i don't think the error is with the code.

Please help!!! Dan

Bird.cs
namespace Treehouse.CodeChallenges
{
    public class Bird
    {
        public string Name { get; set; }
        public string Color { get; set; }
        public int Sightings { get; set; }
    }
}
BirdRepository.cs
using System.Collections.Generic;

namespace Treehouse.CodeChallenges
{
    public static class BirdRepository
    {
        public static List<Bird> LoadBirds = new List<Bird> { new Bird {Name = "Pelican", Color = "White", Sightings = 3}};
    }
}

2 Answers

Kevin Gates
Kevin Gates
14,855 Points

Pulling from another Q&A: https://teamtreehouse.com/community/refactor-the-loadbirds-method-by-using-object-initialization-to-add-the-pelican-to-the-birds-variable

And pull from another answer:

You still need the method, but you'll change how it works. Your object initialization itself is pretty close, but remember that the pelican is an object of type "Bird" (capital "B", no "s"). You'll also need to retain the method's return statement.

A refactored LoadBirds method might look like this:

    public static List<Bird> LoadBirds()
        {
            var birds = new List<Bird>
            {
                new Bird { Name = "Pelican", Color = "White", Sightings = 3 }
            };
            return birds;
        }
Daniel Hunter
Daniel Hunter
4,622 Points

Hey Kevin,

Thanks for your help, that worked perfectly. I would never have figured that out without proper compiler errors to work from šŸ‘