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# Querying With LINQ Functional Programming in C# Actions and Funcs

Taras Metelskii
Taras Metelskii
4,167 Points

Why this doesn't work? FUNC

So i tried to do this and it doesn't work:

using System;
namespace Treehouse.CodeChallenges
{
    public class Program
    {
        public Func<int, int> Square = delegate(int number){
            return number*number; };
    }
}

But this :

using System;
namespace Treehouse.CodeChallenges
{
    public class Program
    {
        public Func<int, int> Square = delegate(int number){
            return number * number; };
    }
}

Worked well. And the only difference is the space between number and *.

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I think the answer might be a little out of the scope of this course, but let me say that the asterisk is a special operator. Not only is it used for common multiplication, but it's also used in references to something we call pointers. These are things that point to a physical address in memory. And they are written like myVariable*. This is not only true for C# but also ANSI C and likely other languages as well.

My best guess here, is that the compiler thought you were trying to reference one of these pointers instead of doing normal multiplication. Going forward, be aware that if you are intending to do multiplication put spaces before and after the asterisks. You can view some information on pointers in C# from this MSDN documentation

Hope this helps! :sparkles:

Taras Metelskii
Taras Metelskii
4,167 Points

So i guessed that " * " is unary operator. And if i tried to pass more then one variable compilator will do all work for me. Thanks for your answer.