BLACKISH DEV BLOG Support
 

 

Standard Arrays can not be typed

A long-time mistake of mine: Trying to type standard arrays like this:

var arr = new Array(int); //stupid – standard arrays can’t be typed

This is very wrong, as it puts the Type Int32 into the newly created array which of course causes problems once you’re trying to get to all those other ints that you stored in the array. So everytime I tried to use this I had to come up with some other solution in the end… converting back and forth from standard to builtin, etc…

The correct way is of course to just create the Array with var arr = new Array(); – then fill it and once you’re trying to use the contents you type each value as you take it out of the array…

Builtin-Arrays on the other hand are typed, so if you don’t need the extra functionality and flexibility, just do it this way:

var posGridA = new int[7]; //builtin arrays are typed!

- Thanks to NCarter for enlightening me!

Bookmark the permalink. Follow any comments here with the RSS feed for this post. Trackbacks are closed, but you can post a comment.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>