创建新类时 ASP.NET 核心 MVC "A namespace cannot directly contain members such as fields or methods"



我创建了一个新的 ASP.NET Core项目,创建了一个文件夹ViewModels,并在里面创建了一个空类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace 10k.ViewModels
{
}

我马上在命名空间下得到一条红色的波浪线,上面写着

"A namespace cannot directly contain members such as fields or methods". 

知道为什么会发生这种情况吗?

命名空间必须以字母开头。如果将 10k 更改为 TenK,它应该可以工作。

尝试重命名命名空间 - 命名空间名称不能以 C# 中的数字开头

如果您尝试运行它,您应该会收到编译器错误。

有关更多信息,请参见此处

此处为非官方 C# 6 参考

相关内容

最新更新