?
Solved

Array & Arraylist

Posted on 2004-08-09
12
Medium Priority
?
2,727 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

801 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