• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What does `this` keyword indicates?

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

    What does `this` keyword indicates?

    1) i see in some indis
    Code:
    this
    keyword:

    Code:
      public string XYZ
            {
                get { return this.ABC;  }
            }
            ......
            private string ABC = ....;
    is it needed at all? what are pros and cons of using that, cant we just use ?


    2) I also see `base` keyword in different methods.. like:

    Code:
                if (State == State.SetDefaults)
                {
                    base.Calculate = Calculate.OnBarClose;
                    base.IsOverlay = (true);
                    .......
                }
    or

    Code:
    (base.Close[3] > base.High[3])
    what happens with or without using that? can you tell me example of cases?
    Last edited by TazoTodua; 02-02-2018, 03:01 AM.

    #2
    Hello. Thank you for the post.

    The 'this' keyword means that you are self-referencing the instance of the object you are working with. Everything in C# is an object and objects have the ability to have multiple instances of themselves (as long as that object is not static).

    Please read this page for more information on the 'this' keyword:
    http://www.c-sharpcorner.com/UploadF...rd-in-C-Sharp/
    https://en.wikipedia.org/wiki/Instan...mputer_science)

    The 'base' keyword is like the 'this' keyword, only it is referencing the parent class that the object inherits.

    Please see these pages on inheritance and the base keyword:
    https://docs.microsoft.com/en-us/dot...ts/inheritance
    https://docs.microsoft.com/en-us/dot.../keywords/base

    Please let us know if you have any questions.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Chris,
      In general I knew that what you are saying.
      I just want to understand, what they do in the indicators, what is the difference, i asked that.

      to see example scenarios, when they matter at all..
      in real-life examples, i dont udnersatnd how or whenever in Ninjatrader `this` or `base` might be needed?

      Comment


        #4
        Hello,

        Thank you for the reply.

        You must use these keywords to be explicit in whatever data you need to get. Using this is an unambiguous way to say "get the variable that belongs to this instance of this object specifically". Here is a publicly available post on the times you would use 'this':
        https://stackoverflow.com/questions/...his-in-a-class

        Using 'base' is used to access methods and properties that the child class does not have. The reason it is used in your example is to access the properties of the Indicator class i.e. the parent class of your indicator.

        Please let us know if we may be of any further assistance.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by donwtrading, Today, 06:23 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by Johnny Santiago, Today, 04:51 PM
        2 responses
        11 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by nekroart, Today, 04:52 PM
        0 responses
        5 views
        0 likes
        Last Post nekroart  
        Started by otislauwaert, Today, 02:43 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_JoshG  
        Started by Johnny, Today, 02:32 PM
        3 responses
        15 views
        0 likes
        Last Post Johnny
        by Johnny
         
        Working...
        X