Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Array & Arraylist

Posted on 2004-08-09
12
Medium Priority
?
2,728 Views
Last Modified: 2008-01-09
whats diffrence between array and arraylist

please give a sample code for both
0
Comment
Question by:Basic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 10

Expert Comment

by:Clif
ID: 11755628
Briefly

Array is a fixed-capacity construct that can have one or more dimensions. The .NET Framework supports multi-dimensional arrays similar to Pascal arrays, and jagged arrays such as you find in C.

ArrayList is a one-dimensional, expandable list that provides some advanced capabilities like the ability to add, insert, or remove multiple items in a single operation.

And not so briefly

Array:
http://www.informit.com/guides/content.asp?g=dotnet&seqNum=115

ArrayList:
http://www.informit.com/guides/content.asp?g=dotnet&seqNum=119
0
 

Author Comment

by:Basic
ID: 11755989
i am creating afunction which returns a array
but it doest working out can u help me
0
 
LVL 10

Expert Comment

by:Clif
ID: 11756070
Show your code.

What error is being thrown (if any)?
What is it doing that it's not supposed to be doing?
What's it not doing that it should be doing?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Basic
ID: 11764618
  Function getArray(ByVal id As Integer) As Array
       
       ....................
          ........................
         
            cmd = New OracleCommand(sql, con)
            dr = cmd.ExecuteReader()
            i = 0
            While dr.Read()
                        myArray(i) = dr("ID")

                       i = i + 1
            End While
            dr.Close()
            con.Close()
       
            Return CType(myArray,Array)


   End Function
0
 
LVL 10

Expert Comment

by:Clif
ID: 11764703
You don't declare myArray (unless that's part of the code that's not shown).
Once you declare it, you shouldn't have to use CType (It should already be an array).
Remember when you return the array, you don't need the parenthesis.

    Good:
    Return myArray

    Bad:
    Return myArray()

0
 

Author Comment

by:Basic
ID: 11764999

i changed

 Return CType(myArray,Array) to

 Return myArray

i am getting this error

Value cannot be null. Parameter name: Argument 'Array' is Nothing.
0
 
LVL 10

Expert Comment

by:Clif
ID: 11765051
Do you declare myArray within the function getArray()?

How do you declare it?

0
 

Author Comment

by:Basic
ID: 11765144
here is the compelte code

 Function getArray(ByVal id As Integer) As Array
       Dim myArray As Array
        Dim sql As String
        openConection()
        sql = "select ID from myTable where empID=" & id
         
            cmd = New OracleCommand(sql, con)
            dr = cmd.ExecuteReader()
            i = 0
            While dr.Read()
                        myArray(i) = dr("ID")

                       i = i + 1
            End While
            dr.Close()
            con.Close()
       
            Return myArray


   End Function
0
 
LVL 10

Accepted Solution

by:
Clif earned 200 total points
ID: 11765481
I think there is more than you are showing.

I tried your code and get a "Object variable or With block variable not set" exception at:
myArray(i) = dr("ID")

Basically you need to instantiate you array before you use it.

I would suggest the following code:

    Function getArray(ByVal id As Integer) As Array
        Dim myArray() As String
        Dim sql As String
        Try
            openConection()
            sql = "select ID from myTable where empID=" & id

            cmd = New OracleCommand(sql, con)
            dr = cmd.ExecuteReader()
 
            Dim i As Integer = 0
            While dr.Read()
                ReDim Preserve myArray(i)
                myArray(i) = dr.Item("ID")
                i = i + 1
            End While
            dr.Close()
            con.Close()
 
            If Not IsArray(myArray) Then
                ReDim myArray(0)
            End If

            Return myArray

        Catch ex As Exception
            Throw ex
        End Try
    End Function
0
 

Author Comment

by:Basic
ID: 11765542
Bingo!........its working
Clif ..thank you for helping even though i have few points to give
0
 
LVL 10

Expert Comment

by:Clif
ID: 11765702
Basic,
I'm sorry, but such a question is highly involved and I just don't have a lot of time at the moment.

No offense, but I think "System.Configuration.ConfigurationSettings.GetConfig" is a bit in depth for you at this point.

Good luck, though.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question