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 CarlTrading, 03-31-2026, 09:41 PM
            1 response
            152 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            87 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            131 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            127 views
            1 like
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            106 views
            0 likes
            Last Post CarlTrading  
            Working...
            X