NexusFi: Find Your Edge


Home Menu

 





saving values from a multi-dimensional array


Discussion in MultiCharts

Updated
    1. trending_up 2,281 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
infe2015
stockholm Sweden
 
Posts: 5 since Mar 2016
Thanks Given: 2
Thanks Received: 1

Hi i need too saving some values in a multi-dimensional array
i have done it i a singel array like this
Upp1 = CUpp[1];
Upp2 = CUpp[2];
Upp3 = CUpp[3];
Upp4 = CUpp[4];
Upp5 = CUpp[5];
CuppSum = Summationarray(CUpp,5);
but i cant find the solution for multi-dimensional.
Thanks Infe


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Warsh Rate Hike at 40%, Iran June 15 Expires Tonight at …
Prediction Markets & Event Contracts
Wood Mackenzie Drops $200 Oil Forecast -- Airspace Expir …
Prediction Markets & Event Contracts
Kalshi Sets $4.13B All-Time Weekly Record as Polymarket …
Prediction Markets & Event Contracts
Memorandum Watch: How the 60-Day MOU Framework Makes May …
Prediction Markets & Event Contracts
Iran Forward Curve: June 30 at 56% vs June 15 at 28% -- …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
16 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
2 thanks
CME Expands 24/7 Trading to WTI Crude Oil and Gold -- We …
1 thanks
30 Sessions
1 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

infe2015,

what exactly seems to be the problem?

When storing values in a multidimensional array the only difference is that you have to specify all dimensions.

For your summation you will likely have to build your own function/code that cycles through all the array elements that you want to sum using a for loop.

Regards,

ABCTG


Follow me on X Reply With Quote
  #3 (permalink)
zaruski
Salt Lake City, UT
 
Posts: 11 since Jun 2017
Thanks Given: 0
Thanks Received: 1


You can certainly achieve this using a recursive method.

BE AWARE, RECURSION CAN BE VERY SLOW AND MEMORY INTENSIVE!

Here is some C# code where I create an array with the following elements:
Element 0: Value 1
Element 1: Array with values 2 and 3
Element 2: Value 4
Element 3: Array with 2 elements:
Element 0: Array with two values: 5 and 6
Element 1: Value 7

The sum should be 28.

static void Main(string[] args)
{
object[] o = new object[4];
int value1 = 1;
object[] array1 = new object[2] {2, 3};
int value2 = 4;

object[] array_2_element_0 = new object[]{5,6};
object[] array2 = new object[2]{array_2_element_0, 7};

o[0] = value1;
o[1] = array1;
o[2] = value2;
o[3] = array2;

int sum = Sum(o);
Console.WriteLine(sum);
}

private static int Sum(object obj)
{
int result = 0;

if (obj is object[])
{
object[] arr = (object[]) obj;
foreach (object o in arr)
{
result += Sum(o);
}
}
if (obj is int)
{
result = (int) obj;
}

return result;
}


Reply With Quote
  #4 (permalink)
zaruski
Salt Lake City, UT
 
Posts: 11 since Jun 2017
Thanks Given: 0
Thanks Received: 1

Also, it just occurred to me, that you might be asking how to access array elements beyond the first dimension. It is done like this:

int x = array[0][0];

However, if you don't know how many dimensions you will have, then you must iterate through every element, rather than access elements by index.


Reply With Quote




Last Updated on August 17, 2017


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts