Click here to Skip to main content
15,906,625 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How would I get the index of the 2D array? For example, I would like to get the index of the spectrumList array at some point below in the code but this doesn't work
int index = spectrumList[j];

C#
for (int j = 0; j < spectrum.spectrum.GetLongLength(1); j++)
                        {
                             double mass = spectrum.spectrum[0, j];
                             double intensity = spectrum.spectrum[1, j];
                             double[] m = new double[2];
                             m[0] = mass;
                             m[1] = intensity;
                             masses[j] = mass;
                             intensities[j] = intensity;
                             spectrumList[j] = m;


                        }
Posted
Comments
BillWoodruff 10-Feb-12 18:51pm    
Until you give us the details of the structure of 'spectrum, I don't think we can help you.

Seeing a construction like "spectrum.spectrum" is ... very strange.

My intuitive sense is that this code could be highly improved by use of Generics.

1 solution

Is spectrumlist a 1D array of ints ? You say 2D array in your question, in which case, spectrumList[j] returns a 1D array, not an int. When you say 'does not work', that is useless. Tell us what happens, what any error message is, etc. I am left guessing what your error is, but I think it's that you need to index the second array to get to an int.
 
Share this answer
 
Comments
BillWoodruff 10-Feb-12 18:47pm    
imho this is a comment to try and help clarify the question asked, and should be posted as a comment, not a solution.
Christian Graus 10-Feb-12 20:55pm    
He says it's a 2D array and he deals with it as a 1D array. So therefore it's very likely that I've told him what is wrong, and I will come back and tell him more, if he gives me enough info to do so. I'm not sure I deserve a 1 vote for giving a probable answer and making a commitment to keep helping until the answer is found.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900