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

William Steele
William Steele
1,739 Points

Instantiation

How do I declare the frog class and give it a name at the same time, tried doing it the way it showed in video but said it was wrong and have been messing around but not finding anything

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

2 Answers

Antonio De Rose
Antonio De Rose
20,884 Points
namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {            
            new Frog == Frog 'mike'
            //when you want to instantiate a class
            //class instancevariable = new kewyword class(), this will lead to the below
            //questions asks you to use the mike word for the instance variable
            //Frog mike = new Frog();

        }
    }
}

William,

I had the same issue as you, and found the answer by removing a sneaky space I had between my class Frog and the (); , after I defined the new variable.

e.g. this was wrong: Frog mike = new Frog ();

but I removed the final space and Treehouse let me have it. My initial method was still valid, but not 100% grammatically/typographically correct.

:)