C #: What `using` request do I need?

I have a project in MS Visual Studio 2008 Pro. I am new to the environment and language, so please ask the noobish question.

I have a type ControlCode:

namespace ShipAILab
{
    public abstract class ControlUnit {

        public enum ControlCode {
            NoAction = 0x00, 
            MoveLeft = 0x01,
            MoveUp = 0x02,
            MoveRight = 0x04,
            MoveDown = 0x08,
            Fire = 0x10,
        }

    }
}

I want this to be available from another class BoardUtilsthat is in the same namespace ShipAILab:

    public static IList<ControlUnit.ControlCode> pathToPoint(IDictionary<CompPoint, int> dist, CompPoint destination) {
          ControlUnit.ControlCode code = ControlUnit.ControlCode.MoveLeft; // works
          ControlCode c2 = ControlCode.MoveDown; // how do I get this to work?
    }

Why does this not work automatically thanks to sharing the namespace? Do I need an operator using? Can I "typedef" as in C rename ControlUnit.ControlCodeto something more compressed?

+3
source share
3 answers

Your listing is inside the class ControlUnit.

, , .

+5

.

namespace ShipAILab
{
    public enum ControlCode {
        NoAction = 0x00, 
        MoveLeft = 0x01,
        MoveUp = 0x02,
        MoveRight = 0x04,
        MoveDown = 0x08,
        Fire = 0x10,
    }

    public abstract class ControlUnit {


    }
}
+4

using, .

Are they in the same DLL (the same project under VS2008). If not, then you need to add the link from the dll pathToPointto the one that declares ControlUnit. You can do this by finding the project in the solution explorer, right-clicking on it and selecting "Add Link ..."

Update

If the code, as shown, really compiles, and you want to do this so that you do not have to type ControlUnit.XYZall over the place, then you need to move the listing declaration out of classControlUnit

+1
source

Source: https://habr.com/ru/post/1731963/


All Articles