C# C# Objects Object-Oriented Programming Initialization

leosa
PRO
leosa
Pro Student 4,622 Points

Error

I keep getting an error, but I am not sure what to type. Here is my error: Frog.cs(7,16): error CS1520: Class, struct, or interface method must have a return type Compilation failed: 1 error(s), 0 warnings

Help is greatly appreciated.

Frog.cs
namespace Treehouse.CodeChallenges
{
    class Frog
    {
        public readonly int TongueLength;

        public TongueLength()
        {
        }
    }
}

2 Answers

Steven Parker
Steven Parker
173,963 Points

Any method other than a constructor must have a return type, and none is given here.

But constructors must have the same name as the class, and since the class is "Frog" and the method name is "TongueLength" the compiler does not consider this to be a constructor and is insisting that a return type must be present.

To create a constructor, you'll have to change the name.

Steven Parker
Steven Parker
173,963 Points

Erik is correct, but it's tricky when you use the same name as the field for your parameter. I'd suggest naming the parameter with the "camel case" version of the name, which makes the assignment less complicated. I believe that's also the naming convention used in the course examples.

I case you're not familiar with the term, the "camel case" version would start with a lower-case letter.

Erik Gabor
Erik Gabor
4,119 Points

James you have to assign a value for the readonly int TongueLength. You can do it also in the constructor.