Wednesday, March 08, 2006

 

Subarrays have no C# value

The multidimensional arrays of C# are supposed to be reference types but behave more like value types. In ASP.NET 2.0, C# is unable to generate subarrays, as in the following example:

int[,] iaValues = { {1, 2}, {3, 4} };
foreach (int iElement in iaValues)
. . .

An attempt to specify "int[] iaSubarray" instead of "int iElement" will fail with a compiler diagnostic. This burdens the programmer to subdivide the array.

As often happens, Microsoft ASP.NET 2.0 documentation is opaque on the order of elements delivered by "foreach" or by an Enumerator. Experimental programming shows that delivery is with last subscript varying most rapidly, first subscript least rapidly, sometimes called "row-wise" by those who think that the first of two dimensions must represent a row index. For the above example, delivery is in the order 1, 2, 3, 4.

Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]