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

Isaac Lau
Isaac Lau
3,767 Points

assign a variable

I have google it for 30 minutes but still can't complete this one.

I guess this should work int Frog = new Frog(); var mike; But not sure the next step.

Program.cs
namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {          

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

1 Answer

Steven Parker
Steven Parker
229,732 Points

You have some extra parts and a few things scrambled up.

  • the instructions ask for an "empty class named Frog", but yours has a "Main" method
  • when initializing a new variable, start with the variable type (such as "Frog") or the keyword "var"
  • after the type, put the name of the variable
  • after the name, an assignment operator ("=")
  • then, to instantiate a class, the keyword "new" followed by the class name
  • finally, after the class name put parentheses to invoke the constructor