错误 CS0246 找不到类型或命名空间名称 'CreateRandomAnswersForKey'(是否缺少 using 指令或程序集引用?)?
Error CS0246 The type or namespace name 'CreateRandomAnswersForKey' 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?)
'''
使用系统;
命名空间TestABRandomness
{
class 测试
{
public 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”是一个静态方法,所以CreateRandomAnswersForKey方法也需要是静态的。如果不指定实例,则不能从静态方法调用实例方法。
正如 John 已经写的那样,您需要在方法调用中删除“new”关键字。
我已经有很长时间没有编码了,但我在这里完全不知所措,即使我知道这是某种简单的错误。谁能帮我吗?我的错误是 Error CS0246 The type or namespace name 'CreateRandomAnswersForKey' could not be found (are you missing a using directive or an assembly reference?)
''' 使用系统;
命名空间TestABRandomness { class 测试 { public 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”是一个静态方法,所以CreateRandomAnswersForKey方法也需要是静态的。如果不指定实例,则不能从静态方法调用实例方法。 正如 John 已经写的那样,您需要在方法调用中删除“new”关键字。