Hello Board,

Not sure if this is titled correctly. I searched the forums with this search term and found nothing. Please excuse any ignorance with respect to language and definitoins as I am less than 1 week into C#.

I am new to programming. I am self teaching c#. The problem arises on one of my first programs that I am doing in order to learn. I certainly don't know all the tools in the C# bag.

I pose my question below and then provide color about the larger scope of the software program. It may be that I am asking the wrong question and there is a better solution than the direction I am going which is what I will call “dynamically declaring variable names” or “on the fly” creation of variable names. If this question means that I am not thinking about this solution to entire program properly, I would not be surprised.

I hope I have simply stated my question below:

How do you name (and declare) and array/list/dictionary that uses values generated from another array in order to concatenate the name for said array/list/dictionary.

Example of problem:

I have a 2D array with the same 5 columns and 5000 rows dropped on my desk every 3 months.

double [,] universeData = new double [5000, 5]

{

{conditionA, conditionB, conditionC, conditionD, column5}

{…...}

{…...}

}

I need to make sub groups of this 5000 item universe conditioned on the rankings from the 4 columns and then create sets from these sub groups that would encompass every conceivable combination of sub group items given the constraints. How can I set this up so I can easily iterate all the combinations?

I can not use a multi dimensional array, because I don't always know the size of the column5 values in each sub group.

Simplified example:

Let's say I had 10 items and a conditionA and a column2.

Create sets from these 10 items if I had 2 items in each set... 3, 4, 5, etc

Find the average of each set.

Now say you split the 10 items into 2 subgroups based on conditionA. Column2 data are the values in the array.

SubGroupA0 = {.10, .05, -.07, .21, .18}

SubGroupA1 = {.30, .12, .10, .03, -.15}

Create sets from these 10 items if I had 2 items in each set AND 1 member in each subgroup A0 and A1. 4 items in each set and 2 in each subgroup. 6 items and 3 members in each etc.

If I am splitting up the universe on just a single condition, I believe I can just make a 2D array [2,5] (as long as item count / subgroup count is a whole number) and then use a nested loop to make the sets of combinations. I always know the parameters of the array – [# of subgroups, array length/# of subgroups] or [2, 10/2]

But let's add another condition, conditionB. Here lies the challenge.

SubGroupA0B0 = {.10, .05}

SubGroupA1B0 = {.10, .03, -.15}

SubGroupA0B1 = { -.07, .21, .18}

SubGroupA1B1 = {.30, .12}

So, the length of the subgroup is dependent on the how the conditions interact with each other.

In this case, I can't use a 3D array [# of sub groups conditionA ,# of sub groups conditionB, column3]

double [,,] subGroup = new double {2, 2, unkown]

Further, using Dictionary failed with subGroup as the Key Name.

To further detail the example:

The sub groups rankings are user defined and let's just say they chose to DECILE all 4 columns.

The user can also choose to remove and then put back sub groups within the universe when doing computations later in the program. (Thus, a List would be ideal?)

1) so in this case I believe there are 10,000 possible sub groups (10^4).

2) subgroups may have have different number of records stored – from 0 to +/-500? (I think in this specific case)

So run some code to find the relevant DECILE rank on the condition1 …thru condition4 columns.

Say the the result for the first item of the 5000 items is:

rankConditionA = 3 // 3 is the decile derived from code not shown

rankConditionB = 0

rankConditionC = 1

rankConditionD = 8

To me these 4 values define a sub group.

string subGroup = '”'rankConditionA+rankConditionB+rankConditionC+rankConditionD'”'

thus subGroup = “3018”

Now within the universe of 5000 items I want to create subgroup arrays with unknown lengths (I think between 0 and 500) that store the value in Column5 of the array named by the above process. In this case "3018"

A side note. I suppose the length could be known by sorting through the array with IF statements and counting each time 0000 or 0001 or 3018 appears. I am assuming this would be a ridiculous amount of IF code for 10,000 subgroups? Any other ways?

– The sub group's [array/list name or dictionary key name] would be the “index” where values of Column 5 are stored.

I can not use the following Dictionary code to load in the column5 values:

for (int i=0; i<=universeData.GetUpperBound(0); i++)

Dictionary <string, double> subGroupData = new Dictionary <sting, double>

subGroupData.Add('”'+subGroup+'”', universeData[i, 4]);

because the variable subGroup is not unique. That is, the first item's Dictionary Key Name is “3018” and maybe it turns out the fiftieth item's Key Name is too.

So what about naming a List variable with resulting subGroup string value?

Use the subGroup variable to declare a LIST named on the value in subGroup, that is now = 3018 in this loop, and then roll through in order to assign the column5 values.

for (int j=0;j<5000;j++) //Loop through the 5000 items

string subGroup = '”'rankConditionA+rankConditionB+rankConditionC+rankConditionD'”'

List<double> [subGroup] = new List <double>(); //[subGroup] here represents its string value not a variable name

[subGroup].Add(universeData[j, 4];

So the idea would be access subGroup column5 values by its LIST variable name using nested loops of 10 (since the user chose to DECILE) for each conditionA/B/C/D to create the 10,000 possible subGroup List names that will call the column5 data.

Note. The use of 10,000 List names maybe a nightmare to run the process to make the sets of combinations given the constraints.

Thanks for looking at this. Peace. Tbone.