简体   繁体   English

在C#vscode中使用指令汇编引用错误丢失

[英]missing using directive assembly reference error in c# vscode

When I try to compile a simple application I made in VSCode with 2 .cs files one with a class, and the other with the main method, I get an error: cannot find type or namespace "MyClass" . 当我尝试使用2个.cs文件和一个main方法编译一个在VSCode中创建的简单应用程序时,出现一个错误: cannot find type or namespace "MyClass" I do not understand why this happens, as I have put both the main method and class declaration in the same namespace. 我不明白为什么会发生这种情况,因为我已经将main方法和类声明都放在了相同的名称空间中。

MyClass.cs MyClass.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace classes_test.src
{
    public class MyClass
    {
        public void testFunc() { Console.WriteLine("Hello World!"); }
    }
}```

Program.cs Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace classes_test
{
    class Program
    {
        static void Main(string[] args)
        {
            MyClass myClass = new MyClass();

            myClass.testFunc();
            Console.WriteLine("Hello World!");
        }
    }
}

I want the console to print Hello World! 我希望控制台打印Hello World! , but instead I get this error. ,但出现此错误。

classes_test.src

and

 classes_test

are not the same Namespace. 不是相同的命名空间。 In order to set your class visible to the main method, you have to use the following using statement. 为了将您的类设置为对main方法可见,您必须使用以下using语句。

using classes_test.src;

This is a quite common mistake, especially for those who are c#-newbie. 这是一个非常普遍的错误,特别是对于那些使用c#-newbie的人。 Including a namespace, DOES NOT include the subnamespaces 包括名称空间,不包含子名称空间

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 你错过了使用指令或程序集引用吗? C#出错 - are you missing a using directive or an assembly reference? Error in C# C#您是否缺少using指令或程序集引用? - C# Are you missing a using directive or an assembly reference? 在C#中的WPF中缺少使用指令或程序集引用 - Missing using directive or assembly reference in WPF in C# c#错误1找不到类型或名称空间名称”(是否缺少using指令或程序集引用?) - c# Error 1 The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?) 错误:您是否缺少使用指令或程序集引用的信息? - error:are you missing using directive or a assembly reference? 错误:缺少using指令或程序集引用? - Error: missing a using directive or an assembly reference? DevExpress 错误缺少 using 指令或程序集引用 - DevExpress error is missing a using directive or an assembly reference 缺少using指令或程序集引用错误 - Missing a using directive or an assembly reference error 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?) C# 错误 CS024 找不到类型或命名空间名称“Form1”(您是否缺少 using 指令或程序集引用?) - C# Error CS024 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM