473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

How do I declare and fill this array?

Ron
I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0

do I just do this:

Dim myarray as int = (5,7,8,9,0)

if not how would i do this?

thanks.

Feb 7 '07 #1
14 18984
Try this in VB.net:
Dim myarray As Integer() = {5,7,8,9,0}
"Ron" <pt*****@yahoo.comwrote in message
news:11*********************@a75g2000cwd.googlegro ups.com...
>I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0

do I just do this:

Dim myarray as int = (5,7,8,9,0)

if not how would i do this?

thanks.

Feb 7 '07 #2
"Ron" <pt*****@yahoo.comschrieb:
>I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0

do I just do this:

Dim myarray as int = (5,7,8,9,0)

if not how would i do this?
\\\
Dim MyArray() As Integer = {5, 7, 8, 9, 0}
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Feb 7 '07 #3
This makes me wonder, what's the difference between:

Dim MyArray() As Integer = {5, 7, 8, 9, 0}

and

Dim myarray As Integer() = {5,7,8,9,0}

thanks,

Doug

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uM***************@TK2MSFTNGP04.phx.gbl...
"Ron" <pt*****@yahoo.comschrieb:
>>I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0

do I just do this:

Dim myarray as int = (5,7,8,9,0)

if not how would i do this?

\\\
Dim MyArray() As Integer = {5, 7, 8, 9, 0}
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 7 '07 #4
"Doug Glancy" <no********@replytogroup.comschrieb:
This makes me wonder, what's the difference between:

Dim MyArray() As Integer = {5, 7, 8, 9, 0}

and

Dim myarray As Integer() = {5,7,8,9,0}
There is no difference except in syntax.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Feb 7 '07 #5
One is correct and the other isn't :)

Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you want. You
want an array of integer types.

Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want a
reference to an integer array.

While both will compile the second is a very ambiguous way to state what you
want.
"Doug Glancy" <no********@replytogroup.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
This makes me wonder, what's the difference between:

Dim MyArray() As Integer = {5, 7, 8, 9, 0}

and

Dim myarray As Integer() = {5,7,8,9,0}

thanks,

Doug

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uM***************@TK2MSFTNGP04.phx.gbl...
>"Ron" <pt*****@yahoo.comschrieb:
>>>I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0

do I just do this:

Dim myarray as int = (5,7,8,9,0)

if not how would i do this?

\\\
Dim MyArray() As Integer = {5, 7, 8, 9, 0}
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Feb 7 '07 #6
Ray,

It is never good for a non native speaking English person to do a discussion
in that language.

But why is: "Create an object while giving it the name MyArray and use for
that an integer array" , not a more realistic way? (The myArray is just a
name, the array() tells the type to use and how many of those)

I have myself not any preference by the way, but telling that one is correct
and the other wrong is something I don't see using your explanation, even in
opposite of that.

Cor

"Ray Cassick" <rc*************@enterprocity.comschreef in bericht
news:OB**************@TK2MSFTNGP02.phx.gbl...
One is correct and the other isn't :)

Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you want. You
want an array of integer types.

Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want a
reference to an integer array.

While both will compile the second is a very ambiguous way to state what
you want.
"Doug Glancy" <no********@replytogroup.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>This makes me wonder, what's the difference between:

Dim MyArray() As Integer = {5, 7, 8, 9, 0}

and

Dim myarray As Integer() = {5,7,8,9,0}

thanks,

Doug

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uM***************@TK2MSFTNGP04.phx.gbl...
>>"Ron" <pt*****@yahoo.comschrieb:
I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0

do I just do this:

Dim myarray as int = (5,7,8,9,0)

if not how would i do this?

\\\
Dim MyArray() As Integer = {5, 7, 8, 9, 0}
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>



Feb 7 '07 #7
"Ray Cassick" <rc*************@enterprocity.comschrieb
One is correct and the other isn't :)

Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you
want. You want an array of integer types.

Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want
a reference to an integer array.

While both will compile the second is a very ambiguous way to state
what you want.
The type of the variable is "integer array". The "()" (read: array) are part
of the type name. The variable type is put after the "As" keyword.
Consequently "As Integer()" (read: As Integer Array) makes more sense.

Armin
PS: There were already many discussions about ambiguous "()" (why are there
no "[]" for arrays like in C#?, why is it different if you specify an upper
bound?), so...

Feb 7 '07 #8
"Armin Zingler" <az*******@freenet.deschrieb:
>One is correct and the other isn't :)

Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you
want. You want an array of integer types.

Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want
a reference to an integer array.

While both will compile the second is a very ambiguous way to state
what you want.

The type of the variable is "integer array". The "()" (read: array) are
part
of the type name. The variable type is put after the "As" keyword.
Consequently "As Integer()" (read: As Integer Array) makes more sense.
Well, I think that both declarations make sense, and I prefer the 'Dim
MyArray() As Integer' declaration for readability reasons (I think it's more
important that a variable contains an array than to read the type of its
items first).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 7 '07 #9
Oh good a trivial argument... you get so few of these on USENET :-) I'm
with Armin on this. If adding part of the variable's type definition onto
the variable name is a good idea then clearly syntax such as the following
would tell us that MyObject is a reference "before" having to see what it is
a reference to.

Dim MyObject* As Form

And as Armin intimates, if an IntegerArray keyword was defined nobody would
be questioning this at all.

Also Armin didn't actually "schrieb" what is stated in Herfried's reply.
The "One is correct and the other isn't :)" quote was written by "Ray
Cassick" <rc*************@enterprocity.comand while I note the grin in his
reply I will suggest that he is correct, he simply selected the wrong
example as the correct one :-) What you have is reference to an integer
array so why not declare it as such?
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
"Armin Zingler" <az*******@freenet.deschrieb:
>>One is correct and the other isn't :)

Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you
want. You want an array of integer types.

Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want
a reference to an integer array.

While both will compile the second is a very ambiguous way to state
what you want.

The type of the variable is "integer array". The "()" (read: array) are
part
of the type name. The variable type is put after the "As" keyword.
Consequently "As Integer()" (read: As Integer Array) makes more sense.

Well, I think that both declarations make sense, and I prefer the 'Dim
MyArray() As Integer' declaration for readability reasons (I think it's
more important that a variable contains an array than to read the type of
its items first).

Feb 8 '07 #10
Hi all,
>What you have is reference to an integer array so why not declare it as
such?
Probably because that this fails
dim myarray as object(4)
and this not
dim myarray(4) as object

this fails as well, while it could be in my idea very proper code

dim myarray() as object() = {{1,3},{2,3}}

Cor
Feb 8 '07 #11
Boy, I suppose that I should have added the 'IMHO' to that response :)

The reason I state the ambiguity is... Try typing them into the IDE and then
hover the mouse over the variable. In BOTH cases the info tip states the
following:

Dim MyArray() As Integer

To me this leads to a specific amount of ambiguity, not something that is
good in code. While I have to admit that I have not looked at the underlying
IL for each case I would have to think that there would be some steps that
need to take place under the covers to 'fix' this.

I guess the bottom line is that *I* like the first one over the second.
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Ray,

It is never good for a non native speaking English person to do a
discussion in that language.

But why is: "Create an object while giving it the name MyArray and use
for that an integer array" , not a more realistic way? (The myArray is
just a name, the array() tells the type to use and how many of those)

I have myself not any preference by the way, but telling that one is
correct and the other wrong is something I don't see using your
explanation, even in opposite of that.

Cor

"Ray Cassick" <rc*************@enterprocity.comschreef in bericht
news:OB**************@TK2MSFTNGP02.phx.gbl...
>One is correct and the other isn't :)

Dim MyArray() As Integer = {5, 7, 8, 9, 0} says exactly what you want.
You want an array of integer types.

Dim MyArray As Integer() = {5, 7, 8, 9, 0} really says that you want a
reference to an integer array.

While both will compile the second is a very ambiguous way to state what
you want.
"Doug Glancy" <no********@replytogroup.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>>This makes me wonder, what's the difference between:

Dim MyArray() As Integer = {5, 7, 8, 9, 0}

and

Dim myarray As Integer() = {5,7,8,9,0}

thanks,

Doug

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uM***************@TK2MSFTNGP04.phx.gbl...
"Ron" <pt*****@yahoo.comschrieb:
>I want to decalre and fill an array with some numbers, 5, 7, 8, 9, 0
>
do I just do this:
>
Dim myarray as int = (5,7,8,9,0)
>
if not how would i do this?

\\\
Dim MyArray() As Integer = {5, 7, 8, 9, 0}
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>




Feb 8 '07 #12
"Tom Leylan" <tl*****@nospam.netschrieb:
Oh good a trivial argument... you get so few of these on USENET :-) I'm
with Armin on this. If adding part of the variable's type definition onto
the variable name is a good idea then clearly syntax such as the following
would tell us that MyObject is a reference "before" having to see what it
is a reference to.
I don't think that the '()' is part of the variable name. Note that you can
specify the bounds there too. However, I believe that the "trivial
argument" is only my personal preference and that others may have different
preferences. That's why it's good that both syntaxes exist.
Also Armin didn't actually "schrieb" what is stated in Herfried's reply.
The "One is correct and the other isn't :)" quote was written by "Ray
Cassick" <rc*************@enterprocity.com>
Sure, that's indicated by the ">>" at the beginning of the quoted line!

However, I do not fully agree with Ray Crassic's opinion although I share
his preference.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 8 '07 #13
"Cor Ligthert [MVP]" <no************@planet.nlschrieb:
>>What you have is reference to an integer array so why not declare it as
such?
Probably because that this fails
dim myarray as object(4)

.... would have be

\\\
Dim MyArray As Object() = New Object(4) {}
///

.... or

\\\
Dim MyArray As New Object(4) {}
///

The curly brackets are necessary because otherwise the compiler cannot
distinguish between object instantiation (a call to the constructor) or
array dimensioning.

As somebody who doesn't want to type and read redundant information, I
prefer 'Dim MyArray(n) As Object'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 8 '07 #14
All,

Thanks for the education. I've decided I'll go with:

Dim() MyArray as Object <g>

Doug

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uL**************@TK2MSFTNGP04.phx.gbl...
"Cor Ligthert [MVP]" <no************@planet.nlschrieb:
>>>What you have is reference to an integer array so why not declare it as
such?
Probably because that this fails
dim myarray as object(4)


... would have be

\\\
Dim MyArray As Object() = New Object(4) {}
///

... or

\\\
Dim MyArray As New Object(4) {}
///

The curly brackets are necessary because otherwise the compiler cannot
distinguish between object instantiation (a call to the constructor) or
array dimensioning.

As somebody who doesn't want to type and read redundant information, I
prefer 'Dim MyArray(n) As Object'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 8 '07 #15

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

Similar topics

4
by: Majid Mohammadian | last post by:
Hi All, I want declare an array of int in SQL Server please help me to convert the following code from VB to TSQL ------------ Dim md_mon(12) As Integer md_mon(1) = 31 ------------- Thanks
6
by: Dylan Nicholson | last post by:
Is there any way of declaring the parameter "array" below to be const, so that the function as written will not compile: void foo(int array /*const*/) { array = array; // should not be allowed...
15
by: b83503104 | last post by:
Hi, class MyClass{ int array_size; HisClass **hisObject; }; I want hisObject to point to an array of HisClass objects. The size of the array is given by array_size.
5
by: Ingo Brueckl | last post by:
I need to declare a fixed array of (already defined and working) sort functions (sortfunc1, sortfunc2, sortfunc3) to pass one element of the array to qsort itself: int index; ??? func =...
3
by: Himmat Solanki via .NET 247 | last post by:
How can we declare an array that have not afix length? and can it possible to inserts new itmes to it? as much as we want to enter. -------------------------------- From: Himmat Solanki ...
8
by: redefined.horizons | last post by:
I would like to have an array declaration where the size of the array is dependent on a variable. Something like this: /* Store the desired size of the array in a variable named "array_size". */...
6
by: pallavi27 | last post by:
HI, i want to declare an array that should accept any size given by the user.how to declare such array?please explain me with the help of a code..it should display on the screen "enter the no of...
2
by: vishwesha.guttal | last post by:
Hi, I am having troble declaring a const array. If the array size is small, then one can do as follows: const double array = {1, 2, 3, 4, 5}; What if I have an array of size say 1000 or...
8
by: Gary | last post by:
When you declare an array of chars and store a string in it, where is the position of the null character \0? And what happens to the unused memory locations? #include <stdio.h> int main(void)...
2
by: Sjoerd | last post by:
On Mon, 08 Sep 2008 00:11:38 -0700, mouac01@yahoo.com wrote: Loop through the array and make an array of all keys. Then loop through the array again and add the missing keys.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
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...
0
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...
0
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,...
0
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...

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.