C# 方法'没有重载;X';接受1个参数

C# 方法'没有重载;X';接受1个参数,c#,C#,我现在在C#面临着一个问题,这让我很烦恼。。 无论如何,这里是代码的一部分 public class blocked { public static void blockedOpcodes() { Dictionary<ushort, String> Opcodes = new Dictionary<ushort, String>(); Opcodes.Add(0x2005, "Blocked: TD46 Tool");

我现在在C#面临着一个问题,这让我很烦恼。。 无论如何,这里是代码的一部分

public class blocked
{
   public static void blockedOpcodes()
   {
    Dictionary<ushort, String> Opcodes
    = new Dictionary<ushort, String>();
            Opcodes.Add(0x2005, "Blocked: TD46 Tool");
    }
}
^但这一条显示了错误“方法“blockedOpcodes”的无重载接受1个参数”

编辑1:我试着改变

   public static void blockedOpcodes()
   {

但另一个错误显示为“无法将类型“void”隐式转换为“bool”

附言:我完全是初学者!我一周前才开始工作


如果有任何帮助,我将不胜感激,谢谢

我不太清楚你到底想达到什么目的。 如果您试图找出词典中是否有
current.Ocpode
,则可能需要如下更改代码:

public class blocked
{
   public static Dictionary<ushort, String> blockedOpcodes()
   {
    Dictionary<ushort, String> Opcodes
    = new Dictionary<ushort, String>();
            Opcodes.Add(0x2005, "Blocked: TD46 Tool");
    }
}
以下是一些有用的链接:

upd

public static bool isOpcodeAllowed(ushort opcode) 
{ 
    //if opcode is 0x2005 and in Opcodes there is a key 0x2005 
    //then the next line will return true
    if (Opcodes.ContainsKey(opcode)) 
    { 
           string text = Opcodes[opcode];
           //there is a string "Blocked: TD46 Tool" in the text variable 
           Console.WriteLine(text); //what do you see here?
           Log1.LogMsg(text); 
           return false; 
     }
     return true; 
 }
Upd2

这不是一个例子这就是为什么您的代码不工作的原因! 你认为这里发生了什么: 操作码.ContainsValue(操作码.ContainsKey(操作码))

首先,您将获得此表达式的值:

Opcodes.ContainsKey(opcode)
价值呢

然后执行
Opcodes.ContainsValue(true)
结果为false,因为您的字典中没有值'true',您在那里有字符串

upd4

如何使用字典:

Dictionary<ushort, string> dict = new Dictionary<ushort, string>();
现在你有一张唱片了。记录具有键和值

值为“Blocked:TD46 Tool”,这是一个
字符串

键是0x2005,这是一个
ushort

dict.ContaintsKey(0x2005)
-返回
true
。因为您的dict中有一个键0x2005

dict.ContaintsKey(0x105)
-返回
false
。因为您的字典中没有0x105键

dict[0x2005]
-返回“Blocked:TD46 Tool”,因为这是一个值或带有键的记录

如果您这样做:

string text = dict[0x2005];
您将得到存储在
text
变量中的“Blocked:TD46 Tool”

现在您可以将
文本
发送到日志,不管是什么控制台

如果你按这里的“播放”
您将看到该代码是有效的。

您说“我正在尝试从字典中获取操作码列表”,但您的代码暗示您实际上正在尝试查找当前操作码是否在字典中。是哪一个?你说得对,ye,我想要的是一个列表,所以当发现操作码时=断开连接并在控制台中写入消息为什么需要列表?安东在下面的回答告诉你如何检查字典中是否有代码。我做到了。但是使用另一种方式,您介意发布一个工作代码来获取操作码的消息吗?公共静态bool isOpcodeAllowed(ushort操作码){if(Opcodes.ContainsKey(opcode)){Log1.LogMsg(X?X?);返回false;}返回true;}不返回。可能是这样的;字符串txt=blockedpcodes.ContainsValue[opcode]@Skipper查看更新。请阅读有关词典的文章。很简单,我看了一下,没找到我想要的。。我想要像这样的东西;Log1.LogMsg(操作码.ContainsValue(操作码.ContainsKey(操作码)));但当然dat不起作用。。因此,如果像containskey这样的操作码或我所理解的xDContainsValue没有给你值,它会给你答案是或否(真或假)。您是否尝试了更新中的代码?你得到了什么?
Opcodes.ContainsKey(opcode)
Dictionary<ushort, string> dict = new Dictionary<ushort, string>();
dict.Add(0x2005, "Blocked: TD46 Tool");
string text = dict[0x2005];