Results 1 to 3 of 3

Thread: [RESOLVED] list.addrange question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Resolved [RESOLVED] list.addrange question

    Hi guys,
    If i have a list of strings and i add the contents of a string array to it, using list.addrange(array) then does it copy the last element (that makes the array without any elements added have a length of 1) because i keep getting a null reference exception and have spent the last 3 hours trying to figure out where the null reference is coming from! lol
    If it does then is there a way to copy all the elements without the null element at the end of the array?

    Thanks for any help
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: list.addrange question

    When you call AddRange it simply adds every element of the array to the List. That's all. It doesn't affect the array in any way whatsoever. If any of the elements of the array are null references then the corresponding item in the List will also be a null reference.

    How about providing some code because your post is just a little confusing? I don't really know where exactly you mean there's a problem: with the array or the List.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: list.addrange question

    Thanks for your reply...but i have managed to come up with a solution. Instead of using list.addrange(array) i have simply replaced it with a for loop and used list.add(array(i)).
    Thank you for your help though


    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

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