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 Object-Oriented Programming Instantiation

Jeremy Katz
Jeremy Katz
2,177 Points

I don't know why I am wrong

Hello, The assignment is to Create a Frog instance in Program.Main() and assign it to a variable named mike. I don't know why I am wrong. Thank you for the help

Program.cs
namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {            
           Frog mike = new Frog ();
        }
    }
Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog
    {

    }
}

3 Answers

Christopher Augg
Christopher Augg
21,223 Points

Heya Jeremy,

It is the space between Frog and ()

Frog mike = new Frog();
Christopher Augg
Christopher Augg
21,223 Points

To clarify, your code compiles in Visual Studio because C# ignores whitespace. You can read about that here .

Therefore, it is the treehouse test that is not passing it correctly as the C# compiler compiles your code for me just fine (Visual Studio Express 2017).

Of course, we should always follow the coding conventions of the languages we use though. That is where we would want to make sure that we are not placing a space between Frog and () as you have done. You can read about coding conventions for c# here .

Regards,

Chris

Patricia Hector
Patricia Hector
42,902 Points

Parenthesis together. When you initialize an object you use the keyword "new" the name of the class and without space in between a pair of parenthesis.

Frog mike = new Frog();

Same thing when you call an existing method

someMethod();

or when you create an array

int[] a = new int[3];

in this case, these are not parenthesis, but brackets. The general idea is the same, do not add a space, otherwise, the compiler won't understand what your code is trying to do.

Jeremy Katz
Jeremy Katz
2,177 Points

Thank you both so much!