【问题标题】:C# Static Class cannot be found找不到 C# 静态类
【发布时间】:2017-12-07 23:04:00
【问题描述】:

我创建了一个静态类来保存我的所有“关卡”数组(我正在使用 XNA 编写一个单机游戏)。

问题是我不能在任何地方使用该类,它只是不会出现在智能感知中,并返回错误The name 'Rooms' does not exist in the current context。知道是什么原因造成的吗?

namespace Marked_V0._2
{
    public static class Rooms
    {
        static public int[,] Level1 = new int[,]
        {
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1 }
        };
    }
}

错误:

CS1002 ; Expected
CS1001 Identifier expected
CS0103 The name 'Rooms' does not exist in the current context.

【问题讨论】:

  • 检查你的命名空间。
  • 无论你想在哪里使用这个类,在那个类的命名空间上方的类的顶部写这个:using Marked_V0._2;
  • 另外,在旁注中,它返回 int[,] 而不是 int,所以请注意您分配给它的内容。

标签: c# class oop static xna


【解决方案1】:

Rooms 的命名空间很可能与项目其余部分的命名空间不匹配。您可以更改命名空间或使用using Marked_V0._2 包含额外的命名空间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多