Announcement

Collapse
No announcement yet.

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.

    #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?)

      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"

          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))

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            566 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            330 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
            548 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X