不能像方法一样使用不可调用的成员“” [英] Non-invocable member '' cannot be used like a method

查看:5418
本文介绍了不能像方法一样使用不可调用的成员“”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临一个问题。
所以我会立即把代码;

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

public static bool isOpcodeAllowed(ushort opcode)
{
lock(locker)
{
if(blockedOpcodes.Contains(opcode))
{
Log1.LogMsg(Oops!有人试图发送一个阻塞的数据包:0x {+ opcode +:X});
return false;
}
return true;
}
}


public static void Load()
{
lock(locker)
{
StreamReader阅读器;
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);
}
}
}
}



这些都在一个叫做Program的类中。我想要做的是从blockedOpcodes收集数据'opcodes'。

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

..



错误:


错误1不可调用的成员Project_name。 Program.blockedOpcodes'
不能像
方法那样使用。 C:\Users\skipper\Desktop\Project_name\without\src2 -
Copy\Project_name\Clients.cs 584 63 Project_name


任何帮助将不胜感激,谢谢!
PS:我是C#的初学者我已经开始了7天前。

解决方案

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



而不是这样:

  if .program.blockedOpcodes(current.Opcode))

因为 blockedOpcodes 是一个列表而不是一个方法。



编辑:你需要比较你的列表值和 0 (或任何您认为是无效值),因为您在列表中存储int值。



编辑:检查给定的OpCode是否在你的列表只需调用这个:

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


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..

解决方案

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

这篇关于不能像方法一样使用不可调用的成员“”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆