• 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

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, 08:00 AM.
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

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

    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.
        DierkNinjaTrader Customer Service

        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


              #7
              The mixed arrays type is removed from .NET 4.0. I have not really seen any use of mixed arrays.


              .Net Training in chennai

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rontronimous, Yesterday, 05:55 PM
              0 responses
              9 views
              0 likes
              Last Post rontronimous  
              Started by bcgeek, Yesterday, 03:43 PM
              2 responses
              6 views
              0 likes
              Last Post bcgeek
              by bcgeek
               
              Started by Mberg, Yesterday, 04:05 PM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_ChrisSch  
              Started by dkbyond, Yesterday, 03:52 PM
              0 responses
              5 views
              0 likes
              Last Post dkbyond
              by dkbyond
               
              Started by Newtrader101, Yesterday, 03:09 PM
              2 responses
              8 views
              0 likes
              Last Post Newtrader101  
              Working...
              X