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

  • Home
  • SEARCH
  • 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 7164657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:06:40+00:00 2026-05-28T14:06:40+00:00

C# allows you to assign values to your enum elements such as public enum

  • 0

C# allows you to assign values to your enum elements such as

public enum Animals
{
    Dog = 0, Cat = 1,
}

And You can cast too and from them like so.

public void demo()
{
    int dog = (int)Animals.Dog;
    Animals cat = (Animals)(dog++);
}

But c# also lets you do things like this

public enum Animals
{
    Dog = Vector2.One, Cat = Vector2.Zero,
}

However you cannot get the Vector2 back in and out with a cast. such as

Vector2 dog = (Vector2)Animals.Dog; //this fails

Is this problem solvable? *Note Vector2 is a class object and Vector2.One and Vector2.Zero are static declarations of such. Which means Dog is assigned to a memory reference.

  • 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-28T14:06:41+00:00Added an answer on May 28, 2026 at 2:06 pm

    The only way that C# will let you do

    public enum Animals
    {
        Dog = Vector2.One,
        Cat = Vector2.Zero
    }
    

    Is if there is an implicit cast from Vector2 to an integral type. Otherwise, you will get a compile error. This is why you cannot cast back to Vector2 – there is no cast from int back to Vector2. Dog and Cat are integer valued, and the values come from the implicit cast from Vector2.One and Vector2.Zero to int, respectively.

    You could define your own explicit cast to make it work, but I’m guessing you won’t be able to get back all the information you want that way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to (or how can I) assign values to a class property
I Want get Param values(src) from Html to AS3 that allows us to maintain
I have a simple object that allows you to assign three properties (x,y,z) (lets
Can I assign a list of strings to a variable for use in an
Python's setdefault allows you to get a value from a dictionary, but if the
I'm trying to make a pie chart that uses values from a user from
ASP.NET MVC allows users the ability to assign permissions to functionality (i.e. Actions) at
I have an application that allows users to create forms and assign validation to
The SQL Server Express 2008 setup allow you to assign different user account for
XAML allows you to specify an attribute value using a string that contains curly

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.