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

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

Where youve written OffenceBox.Text(), you need to replace this with OffenceBox.Text. Its a property, not a method – the clues in the error!

It have happened because you are trying to use the property OffenceBox.Text like a method. Try to remove parenteses from OffenceBox.Text() and itll 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 its 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;
        }
    }
}

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

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

Leave a Reply

Your email address will not be published.