[英]Error CS0246 The type or namespace name 'CreateRandomAnswersForKey' could not be found (are you missing a using directive or an assembly reference?)?
It has been a long time since I've coded, but I am at a complete loss here even though I know it's some sort of simple mistake.自从我编码以来已经有很长时间了,但我在这里完全不知所措,即使我知道这是某种简单的错误。 Can anyone help me out?
谁能帮我吗? My error is 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 指令或程序集引用?)
''' using System; ''' 使用系统;
namespace TestABRandomness { class Test { public static bool[] AnswerKeyArray;命名空间 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;
}
}
} ''' } '''
Method "Main" is a static method, so method CreateRandomAnswersForKey also needs to be static.方法“Main”是一个 static 方法,所以方法 CreateRandomAnswersForKey 也需要是 static。 You cannot call an instance method from a static method without specifying the instance.
如果不指定实例,则不能从 static 方法调用实例方法。 And as John already wrote, you need to remove the "new" keyword in the method call.
正如约翰已经写的那样,您需要删除方法调用中的“new”关键字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.