Results 1 to 4 of 4

Thread: Using list of strings or array of strings

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2009
    Posts
    128

    Using list of strings or array of strings

    Hi,

    I'm migrating from VB6 to VB.NET, in hence my questions below:

    I have to write a function that returns array of strings.

    How can I initiate it to empty array? I need it since I have to check if it's empty array after it returns from this function.

    Is list of arrays better for this purpose? If I use a list - Is it empty when it firstly defined? How can I check it it's empty?

    Thanks in advance

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

    Re: Using list of strings or array of strings

    The point of a List is to provide array-like behaviour with the addition of the ability to dynamically grow and shrink. If you need the ability to grow and shrink but you also must have an array then you can use a List and then call its ToArray method when you're done. A List is empty by default so if you create a new List and call ToArray you will get an array with no elements.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2009
    Posts
    128

    Re: Using list of strings or array of strings

    Thanks.

    Can I use the 'split' function with list? I have to get a string and split it out to dynamic array.

    And how do I check if list is empty?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,296

    Re: Using list of strings or array of strings

    Quote Originally Posted by emc2 View Post
    Can I use the 'split' function with list? I have to get a string and split it out to dynamic array.
    Split returns an array. If you want to split a string and then mess with the results you can use the array to initialise the List. Either pass the array to the constructor when you create the List or else call AddRange and pass the array.
    Quote Originally Posted by emc2 View Post
    And how do I check if list is empty?
    Have you read the documentation for the List class? The answer to that should be pretty obvious if you look at its members.

Tags for this Thread

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