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 trialJoshua Graham
9,882 PointsDid you return the result of 'number * number' in your anonymous method delegate?
I'm pretty sure it's written to return number*number, what am I missing here?
using System;
namespace Treehouse.CodeChallenges
{
public class Program
{
public Func<int, int> Square = delegate(int number)
{
return number*number;
}
}
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! First off, you're doing great! But there's a couple of things going on here. You've forgotten a semicolon which is supposed to be used at the end of the function. And secondly, you need spaces on either side of the *
. Remember, that in C# (and other languages) a *
is not only a multiplication operator but can also be used as pointers to memory addresses. This is what my function looked like:
public Func<int, int> Square = delegate(int number)
{
return number * number;
};
Hope this helps!
Joshua Graham
9,882 PointsJoshua Graham
9,882 Pointsoh...I remember pointers from taking C in college. I guess that would make a difference. thanks