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

Derek Aldana
Derek Aldana
1,095 Points

Some help Setting Value to an array

I cant seem to get this right. I believe I am setting the array value correctly. The count starts at 0 so the 3rd value would be [2]. I believe I am calling the variable correctly? I dont think I fully understand what its asking then.

CodeChallenge.cs
double[] lapTimes = new double[4];
lapTimes[0]=2.2;
double[] finalLapTimes={2.2, 2.3, 2.5, 2.8};
double lap3;
finalLapTimes[2]=lap3;

1 Answer

andren
andren
28,558 Points

You are doing the opposite of what the challenge is asking. It asks you to set the lap3 variable equal to the third value in the finalLapTimes array, whereas you are setting the third value of the finalLapTimes array equal to the value of lap3 (which happens to be completely empty).

To fix it just remove your last line and assign the value stored in "finalLapTimes[2]" to the lap3 variable.

Derek Aldana
Derek Aldana
1,095 Points

ahh!! Haha wow. Shows I have been spending to much time on here lately. Thanks!