简体   繁体   中英

Class in a class? or something else

I was given this little bit of code by my teacher for this weeks lab to help out and sadly it helps a bit but just not enough. In the context im in "selectedType" i'm not sure about and that's not why i'm here. I'm here because I wanna know if someone can explain what "Airplane.Type.Fighter" could be. Airplane is a class connected to this one. But i'm not sure if Type is another class that should be inside of Airplane or not.

Thoughts?

switch (selectedType)
{
  case Airplane.Type.Fighter:
    newPlane = new FighterJet(name, position, cboPlaneType.SelectedItem);
    break;
  case Airplane.Type.Passenger:
    int numPassengers = Utilities.getIntegerInputValue(txtNumberPassengers);
    newPlane =
    new PassengerAirplane(name, position, txtType.Text, txtFlightNumber.Text, numPassengers);
    break;
  default:
    newPlane = new Airplane(name, position);
    break;
  }

Well, we can only guess here. My guess is that Airplane is a property of the current class and that Airplane.Type is an enumeration with values such as FighterJet and Passenger .

As sean pointed out in the comments, it's a good chance that it's an inner enumeration.

public class Airplane
{
    public enum Type
    {
        Fighter,
        Passenger
    }
}

看起来可能是一个enum

You need to write the definitions of Airplane here, to get an answer. This information is insufficient for an answer.

它可以是Class.Enum.EnumType,也可以是Class.Class.Const

It's easy to find out if you look at the definition of the Airplane class. Also, the type of selectedType should give you an indication. If you don't have the source code, Visual Studio can generate a class outline for you if you right click on Airplane.Type.Passenger (for example) and choose "Go To Definition". Also, you can use a tool like Reflector to look at the code.

But, it seems it's a nested enum (the most obvious choice):

class Airplane {
  public enum Type {
    Fighter,
    Passenger
  }
}

But it can also be a nested type with constants:

class Airplane {
  public static class Type {
    public const string Fighter = "Fighter";
    public const string Passenger = "Passenger";
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM