Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using a property without a "set;" ? What does it mean?

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

    Using a property without a "set;" ? What does it mean?

    First of all, I'm NOT really familiar with C#. I didn't find any info about this. What happens if a C# property has a get but does NOT have a set? Sample code from @RSI.CS:
    Code:
    		public Series<double> Avg
    		{
    			get { return Values[1]; }
    		}
    
    		public Series<double> Default
    		{
    			get { return Values[0]; }
    		}
    The code in RSI does write them:
    Code:
    			Default[0]		= value0;
    			Avg[0]		= constant1 * value0 + constant2 * Avg[1];
    So what is happening up there? Just to understand, it is something like the below C++ code?
    Code:
    double& Avg(int index)
    {
        return Values[index+1];
    }
    Certainly, in C++ you would use Avg(1) instead of Avg[1] since it is a function, I'm just curious what the logic actually does in @RSI.cs. Is the get in this case is like a reference so it can also write values via the get or is the set is auto-implemented so writing and reading the above properties is accessing a completely different index or even variable?

    Also, is it standard C# (to not use a set), or is it something that NinjaTrader changed about C#? I don't know if ninjascript is just C# or does it have differences? (C# vs. ninjascript syntax)
    Last edited by accordtrader; 03-04-2018, 06:40 AM.

    #2
    https://www.dotnetperls.com/property may be instructive.

    Comment


      #3
      Hello accordtrader,

      With a get and no set, this will return that object directly, without trying to set the value from the setter.

      This basically gets the first series in the Values collection and returns that whole series.

      That object can then be directly manipulated.


      The brackets indicate an index of a collection, series, or array.

      NinjaScript is C#. These are scripts that inherit from pre-made classes that have methods NInjaTrader will trigger with data behind the scenes.
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

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