Is there any method to find the number of elements that are filled in an array

lets say i have the following array defined

string[] text = new string[50]

and i fill the first 8 elements/indexes

Is there any method that could return the number of elements/indexes within an string array that are filled?

I tried using text.lenght() but that returns the total size of array. In above case it would return 50 which is not what i want...

Hello, gallian99.
I haven't heard about such standard functions :) I can offer two alternative ways for you:
1. Using reference types (like ArrayList). You'll able to add elements dynamically and get the actual size of your array.
2. Create your own structure/class, that will contain your array, the full array size (in your case it's 50) and number of added elements.

Thanks Anteka,

I have tackled it using an alternate already. But I should better try ArrayList as well. Haven't work around with it yet :)

Hello, gallian99.
I haven't heard about such standard functions :) I can offer two alternative ways for you:
1. Using reference types (like ArrayList). You'll able to add elements dynamically and get the actual size of your array.
2. Create your own structure/class, that will contain your array, the full array size (in your case it's 50) and number of added elements.

If you are running on .NET 3, you can use Lists, which are very easy:

List<String> strings = new List<String>(); //initialise the list
strings.Add(str); //Add an item
int length = strings.Count; //how many strings are in the list.

hi
u can do this

int counter=0;  // global value 
while(true)
            {
               
                if (s[counter] != null)
                {
                    comboBox1.Items.Add(s[counter]);
                    counter++;
                }
                else
                {
                    break;
                }
            }

bye

You should follow scru's advice and use a List<T> if you want to have a resizable container.

An ArrayList is also resizable, still usable but a bit "out of date".
If I where you follow the advise off scru and Rashakil Fol.

Thanks!

try this ??? is easy way to find

int I = 0;
foreach (string S in Text)
{
   int I += 1;
}
Console.WriteLine(I.ToString());

try this ??? is easy way to find

Well this is about the dumbest reply I've read on this forum. Did you even read the question?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.