Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

System.DayOfWeek Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    System.DayOfWeek Problem

    Hi,
    In my indicator code have below lines:

    DateTime item3 = base.Time[1];
    int dayOfWeek = item3.DayOfWeek;
    DateTime dateTime3 = Time[0];
    int num = dateTime3.DayOfWeek;

    I got this error:
    Cannot implicitly convert type 'System.DayOfWeek' to 'int'. An explicit conversion exists (are you missing a cast?)

    Above functions not return integer?
    ow to solve that?
    Regards,

    #2
    Hello RezaFx,

    This error returns due to the fact that the DayOfWeek Enum is not an int or string.
    A proper use of DayOfWeek would be the following:
    Code:
    if(dateTime3.DayOfWeek == DayOfWeek.Monday)
    				Print("It is Monday.");
    For information on DayOfWeek please visit the following link: http://www.ninjatrader.com/support/h.../dayofweek.htm

    For a C# reference on DayOfWeek please visit the following link: http://msdn.microsoft.com/en-us/libr...(v=vs.90).aspx

    Please let me know if you have any questions.

    Comment


      #3
      Originally posted by RezaFx View Post
      Hi,
      In my indicator code have below lines:

      DateTime item3 = base.Time[1];
      int dayOfWeek = item3.DayOfWeek;
      DateTime dateTime3 = Time[0];
      int num = dateTime3.DayOfWeek;

      I got this error:
      Cannot implicitly convert type 'System.DayOfWeek' to 'int'. An explicit conversion exists (are you missing a cast?)

      Above functions not return integer?
      ow to solve that?
      Regards,
      If you insist on using an integer, you have to do an explicit cast.
      Code:
      int num = (int)dateTime3.DayOfWeek;

      Comment


        #4
        Thanks. Now it works.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CaptainJack, 05-29-2026, 05:09 AM
        0 responses
        220 views
        0 likes
        Last Post CaptainJack  
        Started by CaptainJack, 05-29-2026, 12:02 AM
        0 responses
        135 views
        0 likes
        Last Post CaptainJack  
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        150 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        235 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        193 views
        0 likes
        Last Post CarlTrading  
        Working...
        X