Brandon Kuczenski
Brandon Kuczenski

Reputation: 985

C# Compiler thinks my property is a method

I am very new to C# and I don't understand what is wrong. I am trying to assign a 'Name' property to my class, and then invoke it, but the compiler says "cannot convert from 'method group' to 'object.'" It should be clear that "Name" is not a method but a property!

C#
namespace Learn_To_Code
{
    public class Elementary_Flow
    {
        // fields:
        TreeView myTreeView;
        // ....

        public Elementary_Flow()
        {
            // construct..
        }

        public string Name
        { 
            get { return myTreeView.Name; }
            set { myTreeView.Name = value; }
        }
        // more code...
    }
    class Learn_To_Code
    {
        [STAThread]
        static void Main()
        {
            Elementary_Flow MyFlow = new Elementary_Flow();
            // following line throws error:
            Console.WriteLine("New Elementary Flow Created. Name: {0}", MyFlow.Name );
        }
    }
}

Upvotes: 0

Views: 177

Answers (2)

gleng
gleng

Reputation: 6304

That's because you are missing a semicolon at the end of the Console.Writeline statement. Add one.

Console.WriteLine("New Elementary Flow Created. Name: {0}", MyFlow.Name );

EDIT

As Steve suggested in the comments, you may want to clean then do another build.

Upvotes: 4

Brandon Kuczenski
Brandon Kuczenski

Reputation: 985

The problem must have lived somewhere other than in the code- I created a new project and copy-pasted the old project into the new project one chunk at a time, and now the new project == the old project but the error does not occur.

sorry for wasting bits.

Upvotes: 0

Related Questions