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 553189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:34:45+00:00 2026-05-13T11:34:45+00:00

Follow along in my test source. What is a good way to get a

  • 0

Follow along in my test source. What is a good way to get a value from a enum object? Must support long. I am attempting without a try/catch block.

enum ELong: long { a = 0x100000000 };
enum ENormal { a = 25 }

        var l = (object) ELong.a;
        var n = (object)ENormal.a;
        //will cast into the correct size
        int ii = (int)n; //ok
        long ll = (long)l; //ok
        //wont cast if its too big
        ll = (long)n; //cast exception
        //or too small
        n = (int)l; //cast exception//compile error. Cannot cast
        //lets try preventing the exception with is
        if (n is int)
            ii = (int)n;//doesnt get here.
        if (n is long)
            ll = (long)n;//doesnt get here.
        if (l is int)
            ii = (int)l;//doesnt get here
        if (l is long)
            ll = (long)l;//doesnt get here
        //WHY!!!!
        //Maybe as will do the trick?
        if (n as int? != null)
            ii = (int)n;//doesnt get here.
        if (n as long? != null)
            ll = (long)n;//doesnt get here.
        if (l as int? != null)
            ii = (int)l;//doesnt get here
        if (l as long? != null)
            ll = (long)l;//doesnt get here
        //geez. What is more stange is (int) will work while (int?) will not
        int? ni = (int?)n;//cast exception
        int iii = (int)n; //works
        ll = (long)n;
  • 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-13T11:34:45+00:00Added an answer on May 13, 2026 at 11:34 am

    Explanation

    if (n is int)
            ii = (int)n;//doesnt get here.
        if (n is long)
            ll = (long)n;//doesnt get here.
        if (l is int)
            ii = (int)l;//doesnt get here
        if (l is long)
            ll = (long)l;//doesnt get here
    

    n and l is neither int/long nor long?/int?, they are of type of your enum, so this is expected behavior.

    Solution

    Probably you should use Convert class to achieve what you want.

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

Sidebar

Related Questions

I'm attempting to follow along with the RestKit unit test guide ( https://github.com/RestKit/RestKit/wiki/Unit-Testing-with-RestKit )
I am attempting to follow along to this tut: HERE but using a sprite
I'm trying to follow along this tutorial from Twilio -->http://www.twilio.com/docs/howto/search-and-buy But, it being written
Is there any way to get interface to play along with custom namespace? Example
Trying to follow along with a metaprogramming screencast from pragpub and ran into some
I'm trying to follow along with Railscasts #235 (Omniauth in a rails app). Having
I am using Xcode 4.3.2 and trying to follow along with the Learn Objective-C
I'm using the Jquery Scroll Follow plugin to allow a box to follow along
Follow up question from Multi-core usage, threads, thread-pools . Are threads moved from one
Follow up from: Directdraw: Rotate video stream I managed to preview the camera's video

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.