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# Lambda Expressions

Frantyk Andrii
Frantyk Andrii
35,423 Points

Action and Func challange step2

What is wrong in my code public static Func<int, int> Square = (number) => number * number;

    public static Action<int, Func<int, int>> DisplayResult = (result,function)=>Console.WriteLine(function(result));
Program.cs
using System;

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

        public Action<int, Func<int, int>> DisplayResult = (result,function)=>Console.WriteLine(function(result));

        static void Main(string[] args)
        {

        }
    }
}

3 Answers

Steven Parker
Steven Parker
231,198 Points

This challenge seems to have an overly-picky syntax checker.

While it's not required by C#, this challenge apparently requires a space in addition to the comma separating the arguments. You might want to report this as a bug to Support.

Also, your top line seems to have a stray static qualifier added in, but the line shown in context does not.

Frantyk Andrii
Frantyk Andrii
35,423 Points

Helm me more pls!! Unit Testing in C# Frantyk Andrii Challenge Task 4 of 4

Implement the Subtract method so that the test passes. using System;

public class Calculator { public double Result;

public Calculator(double number)
{
    Result = number;
}     

public void Add(double number)
{
    Result += number;
}

public void Substract(double number)
{
    Result -= number;
}

}

using Xunit;

public class CalculatorTests { [Fact] public void Initialization() { var expected = 1.1; var target = new Calculator(1.1); Assert.Equal(expected, target.Result, 1); }

[Fact]
public void BasicAdd()
{
    var target = new Calculator(1.1);
    target.Add(2.2);
    var expected = 3.3;
    Assert.Equal(expected, target.Result, 1);
} 
[Fact]
public void BasicSubtract()
{
    var target = new Calculator(1.1);
    target.Substract(0.2);
    var expected = 0.9;
    Assert.Equal(expected, target.Result, 2);
} 

}

Frantyk Andrii
Frantyk Andrii
35,423 Points

Error here

[Fact] public void BasicSubtract() { var target = new Calculator(1.1); target.Substract(0.2); var expected = 0.9; Assert.Equal(expected, target.Result, 2); }

Steven Parker
Steven Parker
231,198 Points

You should create a new question for a new topic, for several reasons:

  • The "view challenge" button at the top is only correct for the first question.
  • When you choose "best answer" it will be clear which question it answers.
  • Others with similar problems might not be able to find the question and answer by title.

Also, be careful to quote your code correctly using the Markdown Cheatsheet.

Frantyk Andrii
Frantyk Andrii
35,423 Points

Thanks, but i decided this question)

Steven Parker
Steven Parker
231,198 Points

I'm not sure what you mean by "decided". It does not look like you have chosen a "best answer" yet.

I did find your new question and I also provided an answer there for you.