【问题标题】:CS0426 The type name ' ' does not exist in the type ' 'CS0426 类型名称 ' ' 不存在于类型 ' '
【发布时间】:2020-03-05 03:11:18
【问题描述】:

我有一个包含此代码的文件:

namespace A
{
    public enum DT
    {
        Byte = 0,
        SByte = 1,
        BCD8 = 2,
        Int16 = 3,
        UInt16 = 4,
        BCD16 = 5,
        Int32 = 6,
        UInt32 = 7,
        BCD32 = 8,
        Single = 9,
        String = 10,
        Structure = 11,
        WString = 12
    }
}

在我的 WebForm1.aspx.cs 文件中,我想使用上面代码中的一个元素。我的 WebForm1.aspx.cs 看起来像:

using A;
namespace SComm
{
    public partial class WebForm1 : System.Web.UI.Page
    {
      protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           A.DT tData = new A.DT.Int16;
           //some other code
        }
    }
}

我收到错误 CS0426:

"类型 DT 中不存在 Int16 类型"

我想是因为不同的命名空间。我应该怎么解决这个错误?

【问题讨论】:

标签: c# asp.net namespaces


【解决方案1】:

在原始帖子中,您声明了一个类型为 A 的变量,但 A 是一个命名空间,并且还使用 new 创建了一个不正确的枚举。对于新的,它正在 A.DT 类型中寻找一个类型“Int16”,这显然不存在。是这样的

A.DT tData = A.DT.Int16; 

【讨论】:

  • 那么如果以上没有回答你的问题,那是什么问题?
  • 你说的我明白了。那我怎么能从枚举中得到Int16呢?
  • 正如我在上面写的那样。请注意,它在 A.DT.Int16 之前没有“新”
  • 所以,我的代码是:A.DT tData=A.DT.Int16,但我收到错误 CS0426 The type name ' ' does not exist in the type ' '
  • 这不是你的问题,你在 A.DT.Int16 之前有一个新的。你是说你得到了上面类型名称''等的错误,即一个空集''
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-26
  • 2010-12-04
  • 2013-08-05
  • 1970-01-01
  • 2022-01-10
  • 1970-01-01
相关资源
最近更新 更多