Are there any differences between using Array.Length and
Array.GetUpperB ound(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. 1 57851
Samuel,
| Are there any differences between using Array.Length and
| Array.GetUpperB ound(0) on a one-dimensional array?
Yes!
Array.Length returns the length of the array (number of elements) you need
to subtract 1 from it to get the UpperBound.
Array.GetUpperB ound(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 "Refactorin g 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.GetUpper Bound).
Hope this helps
Jay
"Samuel R. Neff" <bl****@newsgro up.nospam> wrote in message
news:fa******** *************** *********@4ax.c om...
|
| Are there any differences between using Array.Length and
| Array.GetUpperB ound(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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: elziko |
last post by:
I have a four dimensional array which I am trying to flatten into a single
dimension array:
Dim Array4D(10,10,10,10) as Single
I can create my one dimensional array to be big enough to contain teh data
from the 4D array:
Dim Array2D(Array4D.Length - 1) As Single
|
by: dam_fool_2003 |
last post by:
Hai,
I studied that the array size is fixed. But I come across a word
called "variable length array". Is it possible to change the array
size? So I tried the following:
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int y = { 7, 9,10},i;
for (;i<20;i++)
|
by: OpticTygre |
last post by:
If I have a multidimensional array, such as array1(5, 3), and I want to find
the length of the first section (the 5), can I just use array1.length, or
would that return 15 (5 * 3) instead of 5? Thanks in advance.
|
by: Peter |
last post by:
I want to create a multidemensional arraylist. Seeing as they don't
exist I was wondering if there is a way to create a class that works
like one.
I basically want to use it like this
Dim MyArray as classNewArray
MyArray.add("Data1", "Data2")
or the looping claus....
|
by: sal |
last post by:
Greets, All
Converting array formula to work with datatables/dataset tia sal
I finally completed a formula I was working on, see working code below.
I would like to change this code so it will work with a variable mutl-
row, 5 column datatable where the users select items. Anyone have any
suggestions on where to start?
Or changes in the current code that might be made.
| |
by: zulander |
last post by:
is there a way to find out if the element exist ?
dim myarray() as string
dim mytxt as string
mytxt ="Superman1,Superman2,Superman3,Superman4"
myarray=mytxt.split(",")
debug.print(myarray(4))
|
by: Jerry West |
last post by:
I'd like to get the upper bound index of an integer array. I've tried the
following:
Dim i as Integer
Dim arrayIng() as Integer
i = arrayIng.GetUpperBound
This doesn't work. It seems GetUpperBound behaves more like a function in
that it wants a passed parameter. Is there not a property similar to VB6
|
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= |
last post by:
Hi Willy,
Thank you very much for your work.
C++ code doesnot make any serialization.
So at runtime C# code gives an serialization error at
"msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"
I thought that it is very hard to memory map structure array.
I need both read and write memory mapped file at both side of C# and C++.
|
by: jac130 |
last post by:
the program runs, and user is prompted via inputbox to enter an integer-this is the size of the array, then the user fills the array with that many values...but as the user enters the values, i need to check and make sure that none of hte values have already been entered in the array, if it has..then there must be a message telling user to enter a new value.
EX: user prompted to enter an integer e.g.-2, then user is prompted to enter values...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |