Non-invocable member '' cannot be used like a method

24.6k views Asked by At

I'm facing a problem right naw. So i'll put the code right away;

public static List<ushort> blockedOpcodes = new List<ushort>();

    public static bool isOpcodeAllowed(ushort opcode)
    {
        lock (locker)
        {
            if (blockedOpcodes.Contains(opcode))
            {
                Log1.LogMsg("Oops! Someone tried to send a blocked packet: 0x{" + opcode + ":X}");
                return false;
            }
            return true;
        }
    }


    public static void Load()
    {
        lock (locker)
        {
            StreamReader reader;
            using (reader = new StreamReader("filter.txt"))
            {
                string str = null;
                while ((str = reader.ReadLine()) != null)
                {
                    blockedOpcodes.Add(Convert.ToUInt16(str));
                }
            }
            Log1.LogMsg("Opcode filter loaded!");
            using (reader = new StreamReader("specialip.txt"))
            {
                string item = null;
                while ((item = reader.ReadLine()) != null)
                {
                    specialIPs.Add(item);
                }
            }
        }
    }

So those are in a class called 'Program' What I'm trying to do is collect data 'opcodes' to block from 'blockedOpcodes'

if (Project_name.Program.blockedOpcodes(current.Opcode))

That's where the error shows up..

Error:

Error 1 Non-invocable member 'Project_name.Program.blockedOpcodes' cannot be used like a method. C:\Users\skipper\Desktop\Project_name\without\src2 - Copy\Project_name\Clients.cs 584 63 Project_name

Any help would be appreciated, thank you! PS: I'm a beginner in C# I have started like 7 days ago..

1

There are 1 answers

7
MakePeaceGreatAgain On BEST ANSWER

Obviously you need

if (Project_name.Program.blockedOpcodes[current.Opcode] != 0)

instead of this:

if (Project_name.Program.blockedOpcodes(current.Opcode))

Because blockedOpcodes is a list rather then a method.

EDIT: You need to compare your list-value against 0 (or whatever you consider to be an "invalid" value) because you store int-values within the list.

EDIT: To check if a given OpCode is within your list simply call this:

if (blockedOpcodes.Contains(current.Opcode)) { /* ... */ }