班级里的班级?或其他东西

发布于 2024-10-16 05:02:50 字数 660 浏览 4 评论 0原文

我的老师在本周的实验中为我提供了这一点代码来帮助我,遗憾的是它有一点帮助,但还不够。在上下文中,我在“selectedType”中,我不确定,这不是我在这里的原因。我来这里是因为我想知道是否有人可以解释“Airplane.Type.Fighter”是什么。 飞机是与此相关的一类。但我不确定 Type 是否是另一个应该位于 Airplane 内部的类。

想法?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

柠北森屋 2024-10-23 05:02:50

好吧,我们只能在这里猜测。我的猜测是 Airplane 是当前类的属性,而 Airplane.Type枚举,其值例如 FighterJetPassenger

正如肖恩在评论中指出的那样,这很可能是一个内部枚举。

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.

深海里的那抹蓝 2024-10-23 05:02:50
public class Airplane
{
    public enum Type
    {
        Fighter,
        Passenger
    }
}
public class Airplane
{
    public enum Type
    {
        Fighter,
        Passenger
    }
}
花间憩 2024-10-23 05:02:50

看起来它可能是一个 enum

It looks like it's probably an enum

许久 2024-10-23 05:02:50

你需要在这里写下飞机的定义,才能得到答案。
此信息不足以提供答案。

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

风筝有风,海豚有海 2024-10-23 05:02:50

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

It could be a Class.Enum.EnumType or it can be Class.Class.Const

岁吢 2024-10-23 05:02:50

如果您查看 Airplane 类的定义,就很容易找到答案。另外,selectedType 的类型应该给您一个指示。如果您没有源代码,如果您右键单击 Airplane.Type.Passenger(例如)并选择“转到定义”,Visual Studio 可以为您生成类大纲。另外,您还可以使用 Reflector 之类的工具来查看代码。

但是,它似乎是一个嵌套枚举(最明显的选择):

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

但它也可以是带有常量的嵌套类型:

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

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";
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文