I am trying to figure out how to sort through an array based on a column value and I'm having a hard time figuring out how to do it. For example in the following code I might want to be able to search for something like this.

If the first element of the row = 1 and the second element of the row = 1 and the third element of the row = 2, abs(fourth element) = abs(fourth element) from each of the other rows. I know that might have been kind of confusing.

Basically I want to be able to say if I know that certain row elements are equal to something that I'm looking for I want to be able to find each case of that and then be able to check for the equality of a specific element from that row.

// Constraint Parameters are (tableID,tupleID,constraintID,bound,isEqual,unNormalized).
public Constraints [] c = new Constraints[8];
public void cinit()
{
        //Zero Tuple
    c [0] = new Constraints (1,0,0,0,true,false);// first constraint
    c [1] = new Constraints (1,0,1,-24000,false,false);// second constraint
    c [2] = new Constraints (1,0,2,0,true,false);// third constraint
    c [3] = new Constraints (1,0,3,0,true,false);// fourth constraint
        //First Tuple
    c [4] = new Constraints (1,1,0,2400,false,false);// first constraint
    c [5] = new Constraints (1,1,1,-58150,false,false);// second constraint
    c [6] = new Constraints (1,1,2,-6370,true,false);// third constraint
    c [7] = new Constraints (1,1,3,6370,true,false);// fourth constraint
}

I'm getting really mixed up trying to sort this out. I know I want to have a series of nested for loops to but I'm not quite sure how to do it.

share|improve this question
    
For example; c.Where(x => x.tableID==1) – I4V Apr 26 '13 at 15:51
    
I'm not sure either because your question isn't very clear and you don't show any useful code. The code you show does not contain any 2-D arrays. If you're looking for a value in a 2-D array it only requires a simple nested for loop to look at every index. The comparisons are the same as they always are. The only difference is that you have a loop for columns and a loop for rows, or the other way around. – evanmcdonnal Apr 26 '13 at 15:53
    
Ok so for example I want to find every case where (1,0,dc,check to see if its true,dc) so I can check the value of one of the other elements where that the first to parameters are equal to those specific values. – Macuserman17 Apr 26 '13 at 15:58
    
Ok I finally figured it out. To access an individual element you can just do double val = d.c[0].bound; or int val1 = d.c[0].tableID; Thanks for your help though. where d is a new data object I've created. – Macuserman17 Apr 26 '13 at 16:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.