-
Oct 16th, 2009, 12:57 AM
#1
Thread Starter
Addicted Member
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
-
Oct 16th, 2009, 01:02 AM
#2
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.
-
Oct 16th, 2009, 01:13 AM
#3
Thread Starter
Addicted Member
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?
-
Oct 16th, 2009, 01:19 AM
#4
Re: Using list of strings or array of strings
Originally Posted by emc2
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.
Originally Posted by emc2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|