Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Error CS0161-not all code paths return a value

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

    Error CS0161-not all code paths return a value

    private double calculateRange(double High1, double High2, double Low1, double Low2)
    {

    if( Low1<Low2)
    return High1-Low1;
    if( Low2<Low1)
    return High1-Low2;
    if( High1<High2)
    return High2-Low1;
    if( High2<High1)
    return High1-Low1;

    }

    When I try to compile it gives me 2 errors "cso161 not all code paths return a value" pointing me to the parts in bold. Could somebody please explain what that means and how to fix it?

    #2
    Hello Rdaoogle,

    Thank you for your post.

    When doing a method that returns a value you need to have at least one of the conditions be true.

    Since, all of these conditions could in theory be false, there is nothing to return a value.

    You can out a ELSE statement at the end to return a value to show that none of the conditions were met.

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by rdaoogle View Post
      private double calculateRange(double High1, double High2, double Low1, double Low2)
      {

      if( Low1<Low2)
      return High1-Low1;
      if( Low2<Low1)
      return High1-Low2;
      if( High1<High2)
      return High2-Low1;
      if( High2<High1)
      return High1-Low1;

      }

      When I try to compile it gives me 2 errors "cso161 not all code paths return a value" pointing me to the parts in bold. Could somebody please explain what that means and how to fix it?
      You need a final return directive/value if all your if blocks fall through, using either an else block or an unconditional return.

      Comment


        #4
        yep, that fixed it.
        Thank you both!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by inanazsocial, Today, 01:15 AM
        0 responses
        2 views
        0 likes
        Last Post inanazsocial  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Started by guillembm, Yesterday, 11:25 AM
        2 responses
        10 views
        0 likes
        Last Post guillembm  
        Started by junkone, 04-21-2024, 07:17 AM
        9 responses
        71 views
        0 likes
        Last Post jeronymite  
        Working...
        X