473,749 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

questions about arrays and collections

H,

i'm starting with asp.net/vb.net and have some questions about arrays and
collections:

1) what's the difference between:
dim x() as string
and
dim x as array

2) can variable 'x' in the second case contain anything (string, integer
.... together)?

3) what is the correct syntax?
dim x as arraylist
or
dim x as arraylist()

4) what to choose between:
dim x as array (or if no difference dim x() )
and
dim x as arraylist

5) what to choose between:
dim x as arraylist
and
dim x as list(of string)
Thanks for helping me.
Gilbert

Feb 24 '07 #1
12 1320
Gilbert wrote:
H,

i'm starting with asp.net/vb.net and have some questions about arrays and
collections:

1) what's the difference between:
dim x() as string
and
dim x as array
The difference is that the first one is a reference to a string array,
while the second one is a reference to any kind of array.
2) can variable 'x' in the second case contain anything (string, integer
... together)?
Yes, and no. The reference can be used for any kind of array. If you
assign it an array of strings, you can only put strings in that array.
If you on the other hand assigns it an array of Object, you can put
anything in the array.
3) what is the correct syntax?
dim x as arraylist
or
dim x as arraylist()
That depends on what you want to do. The first one declares a reference
to an ArrayList, the second one declares a reference to an array of
ArrayList objects.
4) what to choose between:
dim x as array (or if no difference dim x() )
and
dim x as arraylist
Again, that depends on what you want to do. The first one declares a
reference to an array (of any type). The second one declares a reference
to an ArrayList.

An ArrayList is good if you want a list that grows dynamically. An array
can not be resized.

If you are using frameword 2.0, you can use a generi list instead of an
ArrayList (unless you want to mix data types in the list). Generics has
made ArrayList almost obsolete.
5) what to choose between:
dim x as arraylist
and
dim x as list(of string)
Guess what? It depends on what you want to do. ;)

An ArrayList is equivalent to a List(Of Object). If you want a list
where you can mix data types, that is what you can use. If you only want
to put strings in the list, you should definitely choose the second one.
--
Göran Andersson
_____
http://www.guffa.com
Feb 24 '07 #2
Thanks for your explanation.
If you don't mind, 2 more questions ...

1)dim x as string() = dim x() as string = an array of string ?

2) dim x as array() = an array of array? Is this the same as dim x( , )?

"Göran Andersson" <gu***@guffa.co mschreef in bericht
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Gilbert wrote:
>H,

i'm starting with asp.net/vb.net and have some questions about arrays and
collections:

1) what's the difference between:
dim x() as string
and
dim x as array

The difference is that the first one is a reference to a string array,
while the second one is a reference to any kind of array.
>2) can variable 'x' in the second case contain anything (string, integer
... together)?

Yes, and no. The reference can be used for any kind of array. If you
assign it an array of strings, you can only put strings in that array. If
you on the other hand assigns it an array of Object, you can put anything
in the array.
>3) what is the correct syntax?
dim x as arraylist
or
dim x as arraylist()

That depends on what you want to do. The first one declares a reference to
an ArrayList, the second one declares a reference to an array of ArrayList
objects.
>4) what to choose between:
dim x as array (or if no difference dim x() )
and
dim x as arraylist

Again, that depends on what you want to do. The first one declares a
reference to an array (of any type). The second one declares a reference
to an ArrayList.

An ArrayList is good if you want a list that grows dynamically. An array
can not be resized.

If you are using frameword 2.0, you can use a generi list instead of an
ArrayList (unless you want to mix data types in the list). Generics has
made ArrayList almost obsolete.
>5) what to choose between:
dim x as arraylist
and
dim x as list(of string)

Guess what? It depends on what you want to do. ;)

An ArrayList is equivalent to a List(Of Object). If you want a list where
you can mix data types, that is what you can use. If you only want to put
strings in the list, you should definitely choose the second one.
--
Göran Andersson
_____
http://www.guffa.com

Feb 24 '07 #3
1)dim x as string() = dim x() as string = an array of string ?
Yes
2) dim x as array() = an array of array? Is this the same as dim x( , )?

dim a as object = x(0)(0) gives in the first situation the first one.
Feb 25 '07 #4
Gilbert wrote:
Thanks for your explanation.
If you don't mind, 2 more questions ...

1)dim x as string() = dim x() as string = an array of string ?
Yes, they are the same.

The first one is the new syntax, where being an array is considered to
be part of the data type. The second one is the old syntax from when
arrays was a special kind of variables.

(Actually the Dim command was originally only used for arrays. Regular
variables was not declared at all.)
2) dim x as array() = an array of array? Is this the same as dim x( , )?
No, it's not the same. An array or arrays is also called a jagged array.

In a jagged array you also have to create each sub-array, while a two
dimensional array is just a single array that is created all at once.

In a jagged array each sub-array can have a different size (hence the
name), while in a two dimensional array the dimensions is the same for
the entire array.

--
Göran Andersson
_____
http://www.guffa.com
Feb 25 '07 #5
Very little correction on your for the rest very fine explanation.
The first one is the new syntax,
The first is a new syntax,

Cor
Feb 25 '07 #6
Indeed. Thanks a lot.
And ... i swear: this is my last question:
Look at this: the first Dim works, the second doesn't: (error)
What do i create with the second Dim and how to use it?

Dim r As Array = Array.CreateIns tance(GetType(I nt32), 101)
r(0) = 3
r(100) = 5

Dim az As Array() = Array.CreateIns tance(GetType(I nt32), 101)
az(0) = 3
az(100) = 5

"Cor Ligthert [MVP]" <no************ @planet.nlschre ef in bericht
news:uz******** *****@TK2MSFTNG P05.phx.gbl...
Very little correction on your for the rest very fine explanation.
>The first one is the new syntax,

The first is a new syntax,

Cor

Feb 25 '07 #7
Cor Ligthert [MVP] wrote:
Very little correction on your for the rest very fine explanation.
>The first one is the new syntax,

The first is a new syntax,

Cor

I don't understand how that is a correction?

You removed "one" which makes it implied, but it's still there.

Then you changed "the new" to "a new", which doesn't change the meaning
of the sentence either.

So, what's the difference?

--
Göran Andersson
_____
http://www.guffa.com
Feb 25 '07 #8
Gilbert wrote:
Indeed. Thanks a lot.
And ... i swear: this is my last question:
Look at this: the first Dim works, the second doesn't: (error)
What do i create with the second Dim and how to use it?

Dim r As Array = Array.CreateIns tance(GetType(I nt32), 101)
r(0) = 3
r(100) = 5

Dim az As Array() = Array.CreateIns tance(GetType(I nt32), 101)
az(0) = 3
az(100) = 5
The second one declares a reference to an array of arrays, then you
create an array of integer and try to assign it to the reference. The
reference is for an array and the object is an array, but the data type
of the arrays differ. Here's how you create an integer array:

Dim az as Integer() = New Integer(100)
or:
Dim az as Integer() = Array.CreateIns tance(GetType(I nt32), 101)

or, just for completeness, using the old syntax:

Dim az() as Integer = New Integer(100)
or:
Dim az() as Integer = Array.CreateIns tance(GetType(I nt32), 101)

--
Göran Andersson
_____
http://www.guffa.com
Feb 25 '07 #9
Ok thanks

"Göran Andersson" <gu***@guffa.co mschreef in bericht
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Gilbert wrote:
>Indeed. Thanks a lot.
And ... i swear: this is my last question:
Look at this: the first Dim works, the second doesn't: (error)
What do i create with the second Dim and how to use it?

Dim r As Array = Array.CreateIns tance(GetType(I nt32), 101)
r(0) = 3
r(100) = 5

Dim az As Array() = Array.CreateIns tance(GetType(I nt32), 101)
az(0) = 3
az(100) = 5

The second one declares a reference to an array of arrays, then you create
an array of integer and try to assign it to the reference. The reference
is for an array and the object is an array, but the data type of the
arrays differ. Here's how you create an integer array:

Dim az as Integer() = New Integer(100)
or:
Dim az as Integer() = Array.CreateIns tance(GetType(I nt32), 101)

or, just for completeness, using the old syntax:

Dim az() as Integer = New Integer(100)
or:
Dim az() as Integer = Array.CreateIns tance(GetType(I nt32), 101)

--
Göran Andersson
_____
http://www.guffa.com

Feb 25 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2031
by: KN | last post by:
I know both are pretty much the same and it comes down to personal choice. But I have to make the choice for the team. Things so far that I am considering 1. XML documentation in C# -- thats good.. not there in VB.net?? 2. Some language features of VB.Net like Redim(makes it easier for developers), but not good enough reason. 3. C# is in more like standard languages and key words used are more
1
3148
by: jose luis fernandez diaz | last post by:
Hi, In the chapter 4 'Collections and Records' of the 'PL/SQL User's Guide and Reference Release 8.1.6' book there is the next paragrap: "For example, PL/SQL supports implicit (automatic) datatype conversion between host arrays and index-by tables (but not nested tables). So, the most efficient way to pass collections to and from the database server is to use anonymous PL/SQL blocks to bulk-bind input and output
10
7044
by: mike | last post by:
If I have 2 object arrays like: var txtobj = theform.getElementsByTagName("input"); var selobj = theform.getElementsByTagName("select"); and i want to iterate over them I'd like to combine them and then iterate over them. so I would do something like this below, but that doesn't look right. var bothobj = txtobj+selobj;
3
9975
by: Kurzweil | last post by:
I need to make a two dimensional array of objects. These objects are of type Influence. How do I declare such an array? Now I use: private object influences; influences = GetInfluences(); // GetInfluences returns type Influence But when I need to use something from te array I have to typecast from
18
40005
by: Mike Bartels | last post by:
Hi Everyone! I have two Arrays A and B. Both arrays are byte arrays with 7 bytes each. The contents of array A and B are the same A = {1, 2, 3, 4, 5, 6, 7}; B = {1, 2, 3, 4, 5, 6, 7}; When I do
1
4152
by: Michael Fitzpatrick | last post by:
Transferring arrays from C DLL's to VB.Net I have a DLL written in C. This DLL reads a text file and creates a several very large arrays, 500,000 points and even larger. I would like the get the data in VB.Net so that I can plot it. Presently I am creating an equally sized array in VB and copying the data from the DLL's array into the VB array. There must be a better way. I looked into using a SAFEARRAY but it looks to me that VB.Net...
1
8705
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections Framework are said to have an element type. http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html
12
1410
by: Gilbert | last post by:
H, i'm starting with asp.net/vb.net and have some questions about arrays and collections: 1) what's the difference between: dim x() as string and dim x as array
15
2493
Samishii23
by: Samishii23 | last post by:
First, images... I have a project that, at this time and version I am working with, I have 648 main stay images, so to say, plus another 100 or so in side features. They are going to stored in a outside .dll. Though I can't figure out if I want to use the Resources feature with C# rather then the "Direct" calling if you will. I have, in many Learning projects in the past have just used the direct call "C:\\Image.jpg" with success, even...
0
8996
marktang
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...
1
9333
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,...
0
9254
tracyyun
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...
0
8256
agi2029
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...
1
6800
isladogs
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...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
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...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.