Wednesday, 15 May 2013

c# - 2-dimensional arrays not assigning values -



c# - 2-dimensional arrays not assigning values -

so have two-dimensional array, or array of arrays, looks this:

public static double[][] arrayofarrays = {jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec};

each of items array looks this:

public static double[] jan = {properties.settings.default.jan1costs, properties.settings.default.jan2costs, properties.settings.default.jan3costs, properties.settings.default.jan4costs, properties.settings.default.jan5cost, properties.settings.default.jan6cost, properties.settings.default.jan7cost};

i'm having problem assigning values arrays. programme compiles , all, these 2 pieces of code produce different results. both of arrays in class called globals.

this method 1:

globals.oct[1] += ar * properties.settings.default.myprice;

and method 2:

globals.arrayofarrays[9][1] += ar * properties.settings.default.myprice;

unless misunderstand 2d arrays, both should same thing, right? however, find method 2 absolutely nil , doesn't save settings. method 1, however, does.

i'd know what's stopping method 2 working, much able save values using datetime.now.month in first array slot, don't need have 12 if/cases different months.

thanks in advance.

try much not value static variables calculate static variable's value. illustration why:

public static int = j * 2; public static int j = 2;

i isn't determinable, 0 because default value of int (j) 0, or because initialization of variables reversed because reason.

change class's code to:

//inside globals.cs's class public static double[][] arrayofarrays; public static double[] jan; ... //all of months' variables, without assignment of course. static globals( ) { jan = {properties.settings.default.jan1costs, properties.settings.default.jan2costs, properties.settings.default.jan3costs, properties.settings.default.jan4costs, properties.settings.default.jan5cost, properties.settings.default.jan6cost, properties.settings.default.jan7cost}; ... //assign here rest months' variables arrayofarrays = {jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec}; }

so of arrayofarrays's arrays referenced same object variables in class.

c#

No comments:

Post a Comment