Results 1 to 6 of 6

Thread: understanding arrays

  1. #1

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591

    understanding arrays

    I'm trying to get a concept of how an array is used in vb.net.

    I read alot, and understand its a list of the same datatype, but I have in my mind its like a grid or something, i think i'm totally off, but what examples could I read to explain how an array is used in coding? Any good tutorials i might have missed?

    Sorry for the ignorance
    Thanks again guys!

  2. #2
    Fanatic Member
    Join Date
    May 2002
    Posts
    746
    You're not wrong in thinking of an array as a grid - esp. when thinking of multidimensional arrays.

    At its simplest though, an array is just a list of objects - be it the built in types (string, int, etc), or your own objects. The grid in this case is just one "column" wide and as many rows as you like.

    So we could have an array of members of drpcken's family and then operate on them (via the array) as a group.
    Last edited by Briantcva; Jun 4th, 2004 at 09:20 AM.

  3. #3
    Member
    Join Date
    Apr 2004
    Posts
    44
    Arrays can also eliminate unnecessary coding.

    without arrays
    Code:
    Private Sub InitalizeVars()
    
    dim var1 as integer = 0
    dim var2 as integer = 0
    dim var3 as integer =0
    dim var4 as integer =0
    .
    .
    .
    dim var500 as integer =0
    end Sub

    with arrays
    Code:
    Private Sub InitalizeVars()
    
            Dim var(499) As Integer
            Dim i As Integer = 0
    
            For i = 0 To 499
                var(i) = 0
            Next
    End Sub
    Compare 500 lines of code to 5. This is a very simplistic example, but that's how you start out learning.

    Jim

  4. #4

    Thread Starter
    Fanatic Member drpcken's Avatar
    Join Date
    Apr 2004
    Location
    devenv
    Posts
    591
    thats awsome

    one more then i think i'll get this: so an array is a temp storage space too? hmm, so that would technically make it a variable, but a group of variables as well.

  5. #5
    Lively Member
    Join Date
    Feb 2003
    Posts
    117
    An array is like a variable, except the memory is still reserved for the number of elements in the array.

    Ie. An Integer array with 20 elements the equivalent of declaring 20 integer variables (in terms of memory).

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    You could think of a 3 dimensional array like this...


    Where the 3 dimensions are length, width and height of the cuboid.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width