如果它是一个子集,是否可以使用一个枚举来代替另一个枚举?

发布于 2025-01-20 10:55:09 字数 457 浏览 1 评论 0原文

假设我们有两个枚举列表:A和B。枚举A是一件衣服的清单,B是A的一个子集。

我可以使用枚举B代替

enum A //Clothes
{
    hats,
    pants,
    shirts,
    gloves,
    jacket,
    boots,
    skirt,
    suit,
    sweater,
    hoodie,
    beanie,
    ...
}

enum B //subset of A, contains only stuff you can put on your head
{
    hats = A.hats,
    beanie = A.beanie,
    ...
}

A吗?

例如,在字典中字典< a,t> foo,我该怎么做:foo [b.hats]

Let's say we have two enum lists: A and B. Enum A is a list of clothes, and B is a subset of A.

Example

enum A //Clothes
{
    hats,
    pants,
    shirts,
    gloves,
    jacket,
    boots,
    skirt,
    suit,
    sweater,
    hoodie,
    beanie,
    ...
}

enum B //subset of A, contains only stuff you can put on your head
{
    hats = A.hats,
    beanie = A.beanie,
    ...
}

Can I use enum B in place of A?

For example, in a dictionary Dictionary<A, T> foo, how can I do: foo[B.hats]?

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

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

发布评论

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

评论(1

青萝楚歌 2025-01-27 10:55:09

您可以在枚举之间进行转换。

foo[(A)B.hats]

You can cast between enums.

foo[(A)B.hats]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文