Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

field initializer

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

    field initializer

    I have the following:

    #region Variables
    public int dotsize = 10;

    private
    Font pfont = new Font("Arial", dotsize, FontStyle.Bold, GraphicsUnit.Point);

    when I place "dotsize" in the code i get an error:

    A field initializer cannot reference the nonstatic field, method, or property

    When I type
    private Font pfont = new Font("Arial", 10, FontStyle.Bold, GraphicsUnit.Point);

    everything is fine. How do I swap the word dotsize for the number 10 ?
    Last edited by velocity; 03-18-2009, 11:04 AM.

    #2
    Is that "publicint" a typo? If not, I believe it should be:

    private int dotsize = 10;
    Last edited by eDanny; 03-18-2009, 07:05 AM.
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      You likely can't do that because dotsize has not been initialized yet.
      Josh P.NinjaTrader Customer Service

      Comment


        #4
        So how do I initialize it?

        (publicint was a typo.)

        Comment


          #5
          You can't. Do it after your dotsize has been initialized in OnBarUpdate() somewhere.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            I'm confused, you say I can't, Then you say I can and to put it after bar update. Still a little puzzled here as to what the code is for initializing dotsize would look like.

            Comment


              #7
              I say you can't meaning not from the Variables section up there.

              Leave your dotsize as is. Move your Font down to OnBarUpdate(). Or just hard set the dotsize in your Font. The point is you can't do it that early. It doesn't know what dotsize is and will only know at runtime. That is why you can't compile.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                ok, I will give it a try. thanks

                Comment

                Latest Posts

                Collapse

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