Wednesday, 15 May 2013

c# - Find length of specific dimension of 2D list -



c# - Find length of specific dimension of 2D list -

i need check length of first dimension of 2 dimensional list of integers 'centrex1' before next loop:

(x = 0; x < (int)centrex1[0].count(); x++) { if (binaryspotsinsidetolerance1[0][x] == 1) { allspotsy.add(centrey1[0][x]); allspotsx.add(centrex1[0][x]); allspotsrlu.add(rluspotsthreshold1[0][x]); } }

an error thrown @ centrex1[0].count() if centrex1 has no members.

you can't count number of elements in centrex1[0], if centrex1 has no elements.

make sure centrex1 has elements in it, before trying access first one.

if (centrex1.any()) // or "if (centrex1.count() > 0)" { (x = 0; x < (int)centrex1[0].count(); x++) { if (binaryspotsinsidetolerance1[0][x] == 1) { allspotsy.add(centrey1[0][x]); allspotsx.add(centrex1[0][x]); allspotsrlu.add(rluspotsthreshold1[0][x]); } } }

c# list multidimensional-array count 2d

No comments:

Post a Comment