Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to: Mixed-type, multidimensional array?

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

    How to: Mixed-type, multidimensional array?

    Sorry to ask a basic programming question, but C# is not my native language.

    I want an array that looks like this:

    Array[1,534.2]="Some string value". So I have Array[number,number]=string.

    How do you do this in C#?

    I tried this:

    private double[,] = new Array[6,6];

    But it seems that the array cannot have a string as a value.
    Last edited by cassb; 11-03-2008, 09:00 AM.
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

    #2
    Please try
    private string[,] myArray = new string[6,6];

    Comment


      #3
      Originally posted by NinjaTrader_Dierk View Post
      Please try
      private string[,] = new string[6,6];
      Tried that:

      Array = new string[6,6];
      Array[0,534.2]="Test";

      Compiling this causes this:
      Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
      cassb
      NinjaTrader Ecosystem Vendor - Logical Forex

      Comment


        #4
        My apologies, edited post below.

        Also array indexes needed to be int not double.

        Note: these are basic C# programming question. Unfortunately we can't provide support level down to that level.

        Comment


          #5
          Originally posted by NinjaTrader_Dierk View Post
          My apologies, edited post below.
          It wants integers for the array subscripts. I can't use a double value for a subscript. Maybe I need an array within an array? I don't understand why this concept is so complex in C#.

          Think of what I'm trying to do as:

          Array[Bar Number,Price] = "Text"
          cassb
          NinjaTrader Ecosystem Vendor - Logical Forex

          Comment


            #6
            Originally posted by cassb View Post
            It wants integers for the array subscripts. I can't use a double value for a subscript. Maybe I need an array within an array? I don't understand why this concept is so complex in C#.

            Think of what I'm trying to do as:

            Array[Bar Number,Price] = "Text"

            Just a note in case someone is looking at this thread in the future -- I decided to just convert the price to an integer and convert it back to double when needed. To convert to integer, where pricedecimals is the number of decimals in TickSize:

            x = Convert.ToInt16(price*(10^pricedecimals))
            Array[0,x]="text"

            To reconvert back to price:

            price = Convert.ToDouble(x/(10^pricedecimals))
            cassb
            NinjaTrader Ecosystem Vendor - Logical Forex

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, 04-17-2024, 06:40 PM
            3 responses
            26 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by bmartz, 03-12-2024, 06:12 AM
            3 responses
            29 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Started by Aviram Y, Today, 05:29 AM
            2 responses
            10 views
            0 likes
            Last Post Aviram Y  
            Started by gentlebenthebear, Today, 01:30 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by cls71, Today, 04:45 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X