C# Querying With LINQ Functional Programming in C# Delegates

sharon smith
sharon smith
10,527 Points

re Code Challenge, instantiation and delegate method

The Code Challenge question says to Instantiate a new MathOperation named add and point it to the Add method.

using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        delegate int MathOperation (int number);

        public static int Add (int number) 
        {
            return number + number;
        }

        static void Main(string[] args)
        {
            MathOperation add = new MathOperation (Add);
        }
    }
}

The error message says Bummer! Did you point to the MathOperation to the Add method?

I think, yes ???

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        delegate int MathOperation (int number);

        public static int Add (int number) 
        {
            return number + number;
        }

        static void Main(string[] args)
        {
            MathOperation add = new MathOperation (Add);
        }
    }
}

3 Answers

Steven Parker
Steven Parker
171,904 Points

Your solution is correct. But the challenge apparently doesn't like the space between the name "MathOperation" and the open parenthesis, just remove that space and you'll pass.

You might want to report this as a bug to Support.

sharon smith
sharon smith
10,527 Points

many thanks / I thought this was correct, and if not, was having real trouble figuring out why

James Churchill
STAFF
James Churchill
Treehouse Teacher

Sharon,

Thanks so much for taking the time to report the bug that you found with this code challenge! I've updated the code challenge so that it'll now allow spaces in your code wherever they're allowed by the compiler.

Thanks, James