Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
218,639 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