|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Array.Length vs Array.GetUpperBound(0) -- any real differences?Array.GetUpperBound(0) on a one-dimensional array? We have a team of developers and most people use Array.Length but one developer uses GetUpperBound(0). I'd like the code to all be consistent but would like to know if there is any other reason I can provide to justify using only Array.Length instead of GetUpperBound(0). I read that Array.Length has special meaning to the compiler in that a loop over an array in C# will bypass bounds checks within the loop since the compiler knows ahead of time that all accesses will be valid. Does VB.NET provide this same optimization? Does it apply only to Length or does it also apply to GetUpperBounds(0). Thanks, Sam B-Line is now hiring one Washington D.C. area VB.NET developer for WinForms + WebServices position. Seaking mid to senior level developer. For information or to apply e-mail resume to sam_blinex_com. Samuel,
| Are there any differences between using Array.Length and Array.Length returns the length of the array (number of elements) you need | Array.GetUpperBound(0) on a one-dimensional array? Yes! to subtract 1 from it to get the UpperBound. Array.GetUpperBound(0) returns the upper bound of the array, you can use it as is... I normally use Array.Length, as other collections have either a Length or Count property. However I have considered changing to GetUpperBound to avoid subtracting 1 from the length. IMHO Which you use in VB.NET is personal preference, however I would be mindful of the "Oddball Solution" smell. The oddball solution smell is described in Joshua Kerievsky's book "Refactoring to Patterns". An oddball solution is when you normally do something one way in a project (Array.Length) but in one section of code you do the same thing (get number of elements in the array) a different way (Array.GetUpperBound). Hope this helps Jay Show quoteHide quote "Samuel R. Neff" <blinex@newsgroup.nospam> wrote in message news:fa6o419oiriknsarj317h2n2t0i5sn1adl@4ax.com... | | Are there any differences between using Array.Length and | Array.GetUpperBound(0) on a one-dimensional array? | | We have a team of developers and most people use Array.Length but one | developer uses GetUpperBound(0). I'd like the code to all be | consistent but would like to know if there is any other reason I can | provide to justify using only Array.Length instead of | GetUpperBound(0). | | I read that Array.Length has special meaning to the compiler in that a | loop over an array in C# will bypass bounds checks within the loop | since the compiler knows ahead of time that all accesses will be | valid. Does VB.NET provide this same optimization? Does it apply | only to Length or does it also apply to GetUpperBounds(0). | | Thanks, | | Sam | | B-Line is now hiring one Washington D.C. area VB.NET | developer for WinForms + WebServices position. | Seaking mid to senior level developer. For | information or to apply e-mail resume to | sam_blinex_com.
activeX doesn't dispose
Controlling MDI toolbars when child forms close ImageList issue delete a record from datagrid unbounded array of objects gets error when instantiating elements detect mouse event on node of a treeview Adding the same file to multiple projects. How can I loop through all of the messages in the inbox - VB.NET E how to submit a form when enter is pressed VB.NET - Automation - DLLs |
|||||||||||||||||||||||