Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7026805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:09:57+00:00 2026-05-28T00:09:57+00:00

I have an enum that looks like the following: public enum EnumWeapons { Fists

  • 0

I have an enum that looks like the following:

public enum EnumWeapons
{
    Fists = new WeaponFists(),
    Sword = new WeaponSword(),
    Bow = new WeaponBow(),
    Staff = new WeaponStaff()
}

Which are derived from the base class Weapon.

Is it possible to use an enum in this way?

If so, will I be able to do something like the following? :

public Weapon weapon = (Weapon)EnumWeapons.Fists;

My attempts haven’t worked as intended, and any help or guidance is appreciated :). Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:09:57+00:00Added an answer on May 28, 2026 at 12:09 am

    This is not possible, the underlying type of an enum are various integral types. From the documentation:

    The approved types for an enum are byte, sbyte, short, ushort, int, uint, long, or ulong.

    Also, I don’t even think what you are trying to do makes sense. When you want a weapon, do you really want the same instance every time? I doubt it.

    What you really want, I think, is a factory. In it’s most naive form, you can say:

    public enum WeaponType {
        Fists,
        Sword,
        Bow, 
        Staff
    }
    
    public class WeaponFactory {
        public Weapon Create(WeaponType weaponType) {
            switch(weaponType) {
                case WeaponType.Fists:
                    return new WeaponFists();
    
                case WeaponType.Sword:
                    return new WeaponSword();
    
                case WeaponType.Bow:
                    return new WeaponBow();
    
                case WeaponType.Staff:
                    return new WeaponStaff();
    
                default:
                    throw new ArgumentOutOfRangeException("weaponType");
            }
        }
    }
    

    Now you can say:

    var weapon = weaponFactory.Create(WeaponType.Fists);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an enumeration that looks like the following public enum MyEnum { A,
I have a c# enumeration that looks like this: public enum EthernetLinkSpeed { [Description(10BASE-T)]
I have an enum that looks a little bit like this: public enum Numbers
I have an enum that looks as follows: public enum TransactionStatus { Open =
I have a class that defines its own enum like this: public class Test
I have a source object that looks like this: private class SourceObject { public
I am using an enum singleton that looks (somewhat) like this: public enum mySingleton{
I have an enum that looks like this: enum foo{ a=0, b=1, c=2, d=4
I have created a class Person that looks like this: public class Person {
I have a ViewModel that looks like this: public class CreateReviewViewModel { public string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.