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,856 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();

        }
    }
}
Ed H-P
Ed H-P
2,557 Points

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.

:)