469,646 Members | 1,136 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

"Current" item in Array?

darn stuck again!
in my string array
string[] myArray = string[26];

Let's say I've put a string field into the first 3 items and I guess the
other 23 must then be null, right? OK so is there any C# method/property to
find the next empty (null) item? The Length property always returns the
total items ie 26!
Nov 16 '05 #1
4 4429
int HighestUsed(string[] ary)
{
for(int i = 0; i< ary.Length; ++i)
if (ary[i] == null)
return i;
return ary.Length;
}
--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"Davids" <db****@simnet.is> wrote in message
news:eq**************@TK2MSFTNGP14.phx.gbl...
darn stuck again!
in my string array
string[] myArray = string[26];

Let's say I've put a string field into the first 3 items and I guess the
other 23 must then be null, right? OK so is there any C# method/property to find the next empty (null) item? The Length property always returns the
total items ie 26!

Nov 16 '05 #2
Hi,

Why don't you use the ArrayList to put strings into?
Standard arrays (e.g. string[]) have constant length,
so you can't use "Length" to find empty elements.
Real problem starts with value type's arrays that
initialize its values (e.g. int[])

Other solution is to keep "current index" in a variable.

HTH
Marcin
darn stuck again!
in my string array
string[] myArray = string[26];

Let's say I've put a string field into the first 3 items and I guess the
other 23 must then be null, right? OK so is there any C# method/property to
find the next empty (null) item? The Length property always returns the
total items ie 26!

Nov 16 '05 #3
exactly that just thought maybe there was some built in function to do
this...
"James Curran" <Ja*********@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
int HighestUsed(string[] ary)
{
for(int i = 0; i< ary.Length; ++i)
if (ary[i] == null)
return i;
return ary.Length;
}
--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"Davids" <db****@simnet.is> wrote in message
news:eq**************@TK2MSFTNGP14.phx.gbl...
darn stuck again!
in my string array
string[] myArray = string[26];

Let's say I've put a string field into the first 3 items and I guess the
other 23 must then be null, right? OK so is there any C# method/property

to
find the next empty (null) item? The Length property always returns the
total items ie 26!


Nov 16 '05 #4
Davids,
Have you tried Array.IndexOf?

Something like:
string[] myArray = string[26];
int index = Array.IndexOf(myArray, null);

Hope this helps
Jay

"Davids" <db****@simnet.is> wrote in message
news:eq**************@TK2MSFTNGP14.phx.gbl... darn stuck again!
in my string array
string[] myArray = string[26];

Let's say I've put a string field into the first 3 items and I guess the
other 23 must then be null, right? OK so is there any C# method/property
to find the next empty (null) item? The Length property always returns the
total items ie 26!

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by VB Programmer | last post: by
3 posts views Thread by RR | last post: by
1 post views Thread by Peter Knörrich | last post: by
4 posts views Thread by pamelafluente | last post: by
3 posts views Thread by Bob Cohen \(106531\) | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.