![](/img/trans.png)
[英]error CS0246: The type or namespace name 'Npgsql' could not be found (are you missing a using directive or an assembly reference?)
[英]Error CS0246 The type or namespace name 'CreateRandomAnswersForKey' could not be found (are you missing a using directive or an assembly reference?)?
自从我编码以来已经有很长时间了,但我在这里完全不知所措,即使我知道这是某种简单的错误。 谁能帮我吗? 我的错误是错误 CS0246 找不到类型或命名空间名称“CreateRandomAnswersForKey”(您是否缺少 using 指令或程序集引用?)
''' 使用系统;
命名空间 TestABRandomness { class 测试 { 公共 static bool[] AnswerKeyArray;
public static void Main()
{
AnswerKeyArray = new CreateRandomAnswersForKey();
}
bool[] CreateRandomAnswersForKey()
{
bool[] returnArray = new bool[100];
Random rand = new Random();
for (int i = 0; i < 100; i++)
{
returnArray[i] = rand.Next(2) == 1;
}
return returnArray;
}
}
} '''
方法“Main”是一个 static 方法,所以方法 CreateRandomAnswersForKey 也需要是 static。 如果不指定实例,则不能从 static 方法调用实例方法。 正如约翰已经写的那样,您需要删除方法调用中的“new”关键字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.