2

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...

  • It is a simple and common mistake, easy to find on google... – Pozzo Apps Jun 28 '13 at 14:03
  • `int dayNumber = day.ordinal();` – Shark Jun 28 '13 at 14:05
  • I think it's not that easy to find it on Google because I've been searching for 2 days. ordinal method doesn't exist and I have the latest dot42 framework. Thanks anyway... – Muhammad Fayed Jun 28 '13 at 14:17
  • Forgot to say that ... This type of casting is being neglected by the dot42 convertal for some reason.. so the whole line is not ported into the apk. I can get to the error using watches or Convert.ToInt32(day); – Muhammad Fayed Jun 28 '13 at 14:52

1 Answers1

2

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.

Piotr Kula
  • 9,597
  • 8
  • 59
  • 85
  • Thanks a lot for helping.. Your code works. Now, The way I see it that variables which are never used are being omitted through the conversion.. this doesn't work : protected override void OnCreate(Bundle savedInstance) { Days day = Days.Sun; int dayNumber = (int)day; base.OnCreate(savedInstance); SetContentView(R.Layouts.MainLayout); } .... – Muhammad Fayed Jun 28 '13 at 17:36
  • but this does : protected override void OnCreate(Bundle savedInstance) { Days day = Days.Sun; int dayNumber = (int)day; dayNumber++; // any expression with the variable base.OnCreate(savedInstance); SetContentView(R.Layouts.MainLayout); } If you have the time to shed some lights on this issue. That would be nice of you. Appreciate your help.. – Muhammad Fayed Jun 28 '13 at 17:37