Ionut
Ionut

Reputation: 843

CS0426 The type name ' ' does not exist in the type ' '

I have a file with this code:

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
    }
}

In my WebForm1.aspx.cs file, I want to use an element from code above. My WebForm1.aspx.cs looks like:

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
        }
    }
}

I get the error CS0426:

"The type Int16 does not exist in the type DT"

I suppose is because of the different namespaces. What should I do solve this error?

Upvotes: 3

Views: 6873

Answers (1)

Tim Rutter
Tim Rutter

Reputation: 4679

In the original post you were declaring a variable of type A but A is a namespace and also using new to create an enum which is not correct. With the new it is looking for a type "Int16" in the type A.DT which obviously does not exist. Its like this

A.DT tData = A.DT.Int16; 

Upvotes: 1

Related Questions