Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

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

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:UsersskipperDesktopProject_namewithoutsrc2 - CopyProject_nameClients.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..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)) { /* ... */ }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...