Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

local method inside OBU?

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

    local method inside OBU?

    Hi,

    I'm trying to clean up some code and pull out long sections of code inside OBU, and paste them into functions (methods) at the end of OBU. I think this is called creating local methods.

    A sample local method:
    Code:
    // Declare a local function.
             string AppendPathSeparator(string filepath)
             {
                if (! filepath.EndsWith(@"\"))
                   filepath += @"\";
    
                return filepath;   
             }
    but the compiler complains I am missing a closing curly at the line of code right before the declaration of the local function.

    Is it possible to create local methods inside OBU?

    If not, is my only choice to move it outside of OBU, and use an access modifier of private protected?

    thank you

    #2
    nope, appears i can't use private protected, just 1 modifier, protected...

    Comment


      #3
      Hello. Thanks for the note.

      You must define the method at the class level, like so:

      Code:
      protected override void OnBarUpdate()
      		{
                            ...			
      		}
      		
      		protected  string AppendPathSeparator(string filepath)
                      {
                          if (! filepath.EndsWith(@"\"))
                            filepath += @"\";
      
                          return filepath;   
                       }
      Please let us know if you have any questions.

      Comment


        #4
        I got the idea from this MSDN https://docs.microsoft.com/en-us/dot...ocal-functions


        Starting with C# 7, local functions

        So I'm assuming NT ver 8 is not using this level of c# yet.

        thanks

        Comment


          #5
          Hello.

          Thanks for the reply.

          The supported C# syntax is for .NET 3.5 and 4.5 so local functions are not supported.

          Please let us know if we may be of any further assistance.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          43 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          25 views
          0 likes
          Last Post PaulMohn  
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          163 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          98 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          158 views
          2 likes
          Last Post CaptainJack  
          Working...
          X