c# - Serializing jagged vs multidimensional arrays -


i have object of type array (that object.gettype().isarray returns true). question how can find out whether jagged or multidimensional array? there way serialize array code "doesn't know" difference (using reflection)?

note array of arbitrary length/dimension. thinking perhaps parse type.name search [, (as in 1 part of [,,]) or [][] distinguish between these -- still means i'll have 2 code paths each case , feel there should better way accomplish parsing type names.

for jagged array, seems easy enough take array , keep indexing using [] iterate on elements, however, approach not work multidimensional arrays.

a jagged array array of arrays. have @ element type , check array well:

    static bool isjaggedarray(object obj) {         var t = obj.gettype();         return t.isarray && t.getelementtype().isarray;     }      static void test() {         var a1 = new int[42];         debug.assert(!isjaggedarray(a1));         var a2 = new int[4, 2];         debug.assert(!isjaggedarray(a2));         var a3 = new int[42][];         debug.assert(isjaggedarray(a3));     } 

cast array , use rank property find number of dimensions multi-dimensional array.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -