Search code examples
c#androiddot42

Can't cast enum to int dot42


I'm evaluating the use of dot42 framework to target android using C#.. So while going through what dot42 can and can't do, I got stuck with the following casting not working.. throws Java expression error.

 public enum Days { Sat = 1, Sun, Mon }

 Days day = Days.Sun;
 int dayNumber = (int)day; // <----- Throws Error

Is there any way around this ?

Thanks...


Solution

  • Are you sure you are on version 1.0.0.70?

    The following test code runs OK here.

    namespace TestDays
    {
        [Activity]
        public class MainActivity : Activity
        {
            protected override void OnCreate(Bundle savedInstance) 
            {
                base.OnCreate(savedInstance);
                testDays();
                SetContentView(R.Layouts.MainLayout);
            }
    
                    public enum Days { Sat = 1, Sun, Mon }
    
            public int testDays() 
            {
                Days day = Days.Sun;
                int dayNumber = (int)day; // <----- Throws Error
                return dayNumber;
            }
    
       }
    }
    

    Disclosure: I work for dot42.