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# Objects Encapsulation and Arrays Arrays

C# Objects Array Challenge Help.

I don't know if it's just me not understanding the question, or if I am just reading it wrong. Originally I thought I was suppose to set the value of the third item in the array, like a key-value pair. Then I read it again and it seems like I am suppose to set lap3 as type double and add the third item in that way. I keep getting an error that asks me if I indexed into the third item of the 'finalLapTimes' array and I did. So I am at a lost for words on what I am doing wrong.

CodeChallenge.cs
double[] lapTimes = new double[4];
lapTimes[0] = 2.2;


double[] finalLapTimes = new double[4] {2.2, 2.3, 2.5, 2.8};
double lap3 = 2.5;
finalLapTimes[2] = lap3;

3 Answers

Your code should look like this:

double[] lapTimes = new double[4]; lapTimes[0] = 2.2;

double[] finalLapTimes = new double[4] {2.2, 2.3, 2.5, 2.8}; double lap3 = finalLapTimes[2];

Yes this does actually work. Thank you! It looks like I was really close to the answer.

Thank you for responding to me, but that doesn't work. lap3 has to be the third item in the array finalLapTimes. Setting finalLapTimes array call to 1 would be the second item in the array.

Sorry about that, I amended my answer :)

double[] lapTimes = new double[4]; lapTimes[0] = 2.2;

double[] finalLapTimes = new double[4] {2.2, 2.3, 2.5, 2.8}; double lap3 = finalLapTimes[2];

The assignment is "Declare and initialize another array of doubles named finalLapTimes with the following times: 2.2, 2.3, 2.5, 2.8." and there's no mention of "double lap3 = finalLapTimes[2];". Could you tell me how "double lap3 = finalLapTimes[2];" was relevant since the question/assignment mentioned nothing about that?

As it turns out that's relevant to question 4/4 but I couldn't get past 3/4 without it. How did you know?