[c#] Non-invocable member cannot be used like a method?

I keep getting the following errors in my program:

'System.Windows.Forms.TextBox.Text' is a 'property' but used like a 'method'

and

Non-invocable member 'System.Windows.Forms.Control.Text' cannot be used like a method.

Here is the code:

if (OffenceBox.Text != "")
   {
 AddBook(int.Parse(AgeBox.Text), NameBox.Text, AddressBox.Text, (HeightBox.Text), OffenceBox.Text());
   }
   else
   {
   MessageBox.Show("Age must be max 3 numbers in length");
   }
   }

How can I fix this problem?

EDIT: Fixed the error and now encountered another: Argument 4: Cannot convert String to int and I can't seem to fix the problem.

This question is related to c#

The answer is


As the error clearly states, OffenceBox.Text() is not a function and therefore doesn't make sense.


It have happened because you are trying to use the property "OffenceBox.Text" like a method. Try to remove parenteses from OffenceBox.Text() and it'll work fine.

Remember that you cannot create a method and a property with the same name in a class.


By the way, some alias could confuse you, since sometimes it's method or property, e.g: "Count" alias:


Namespace: System.Linq

using System.Linq

namespace Teste
{
    public class TestLinq
    {
        public return Foo()
        {
            var listX = new List<int>();
            return listX.Count(x => x.Id == 1);
        }
    }
}


Namespace: System.Collections.Generic

using System.Collections.Generic

namespace Teste
{
    public class TestList
    {
        public int Foo()
        {
            var listX = new List<int>();
            return listX.Count;
        }
    }
}


I had the same issue and realized that removing the parentheses worked. Sometimes having someone else read your code can be useful if you have been the only one working on it for some time.

E.g.

  cmd.CommandType = CommandType.Text(); 

Replace: cmd.CommandType = CommandType.Text;