不可调用成员 '' 不能像方法一样使用 [英] 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);
}
}
}
}
所以这些都在一个名为程序"的类中我想要做的是收集数据操作码"以阻止blockedOpcodes"
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..
错误:
错误 1 不可调用成员Project_name.Program.blockedOpcodes"不能像方法.C:UsersskipperDesktopProject_namewithoutsrc2 -复制Project_nameClients.cs 584 63 Project_name
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
如有任何帮助,将不胜感激,谢谢!PS:我是 C# 的初学者,我 7 天前就开始了..
Any help would be appreciated, thank you! PS: I'm a beginner in C# I have started like 7 days ago..
推荐答案
显然你需要
if (Project_name.Program.blockedOpcodes[current.Opcode] != 0)
而不是这个:
if (Project_name.Program.blockedOpcodes(current.Opcode))
因为 blockedOpcodes
是一个列表而不是一个方法.
Because blockedOpcodes
is a list rather then a method.
您需要将列表值与 0
(或任何您认为无效"的值)进行比较,因为您将整数值存储在列表中.
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.
要检查给定的操作码是否在您的列表中,只需调用:
To check if a given OpCode is within your list simply call this:
if (blockedOpcodes.Contains(current.Opcode)) { /* ... */ }
这篇关于不可调用成员 '' 不能像方法一样使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!