简体   繁体   English

错误 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?)?

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.

相关问题 错误 CS0246:找不到类型或命名空间名称“Npgsql”(您是否缺少 using 指令或程序集引用?) - error CS0246: The type or namespace name 'Npgsql' could not be found (are you missing a using directive or an assembly reference?) 错误CS0246找不到类型或名称空间名称“ Windows”(是否缺少using指令或程序集引用?) - Error CS0246 The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246:找不到类型或命名空间名称“StreamingContext”(是否缺少 using 指令或程序集引用?) - Error CS0246: The type or namespace name 'StreamingContext' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246:找不到类型或命名空间名称“IWebHostEnvironment”(您是否缺少 using 指令或程序集引用?) - error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246:找不到类型或命名空间名称“BannerPosition”是否缺少 using 指令或程序集引用? - error CS0246: The type or namespace name 'BannerPosition' could not be found are you missing a using directive or an assembly reference? CS0246:找不到类型或命名空间名称&#39;MySql&#39;(您是否缺少using指令或程序集引用 - CS0246: The type or namespace name 'MySql' could not be found (are you missing a using directive or an assembly reference CS0246:找不到类型或名称空间名称“ Employee”(您是否缺少using指令或程序集引用?)? - CS0246: The type or namespace name 'Employee' could not be found (are you missing a using directive or an assembly reference?)? CS0246 找不到类型或命名空间名称“ErrorViewModel”(您是否缺少 using 指令或程序集引用?) - CS0246 The type or namespace name 'ErrorViewModel' could not be found (are you missing a using directive or an assembly reference?) C# 错误:错误 CS0246 找不到类型或命名空间名称“”(您是否缺少 using 指令或程序集引用?) - C# Error: Error CS0246 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?) 错误CS0246:找不到类型或名称空间名称“ AForge”。 您是否缺少using指令或程序集引用? - error CS0246: The type or namespace name `AForge' could not be found. Are you missing a using directive or an assembly reference?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM