Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

get and set in Properties

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

    get and set in Properties

    Hello,
    I have a question I should have asked a long time ago. Can someone please explain this section of code to me. It's pretty common among indicators. Thanks.
    [Description("Number of bars used for calculations")]
    [GridCategory("Parameters")]
    public int Period
    {
    get { return period; }
    set { period = Math.Max(1, value); }
    }

    #2
    Hello CaptainAmericaXX,

    Thanks for your post.

    [Description("Number of bars used for calculations")] - This will provide "help" text that appears in the box below the indicator parameters. When you click on the specific parameter, this help text,"Number of bars used for calculations" would appear.

    [GridCategory("Parameters")] - Identifies what section the property will appear in.

    public int Period - This is a variable declaration where public means that it can be seen outside of the ninjascript (such as the user interface panel or if other ninjascript calls this ninjascript). int declares the variable named Period an Integer type.

    get { return period; } - This gets (retrieves) the value stored in the private int variable named "period". The private variable named "period" must be declared in your regions variable. This is the variable your code would work with

    set { period = Math.Max(1, value); } - This will set the value of Period and period according to the greater of 1 or the value of Period.

    Together the get/set make the Period property a read/write type.

    Here is a link to a more formal generic answer on the get/set accessors: https://msdn.microsoft.com/en-us/library/w86s7x04.aspx

    Comment


      #3
      Thanks Paul,
      So what is the "value" in the statement:
      set { period = Math.Max(1, value); }
      value is never declared anywhere in the code.
      Last edited by CaptainAmericaXX; 02-02-2017, 09:06 PM.

      Comment


        #4
        Hello CaptainAmericaXX,

        Thanks for your reply.

        Sorry I missed that.

        Here is a link for clarity on the use of value: https://msdn.microsoft.com/en-us/library/a1khb4f8.aspx

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        560 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        325 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X