473,414 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

"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 4596
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Don G | last post by:
Within the menu for my site, I have inserted 'class="current"' within the link for the current page. So the link looks somthing link: <li><a href="index.php" class="current">Home</a></li> The...
1
by: VB Programmer | last post by:
When my users login I want them to be able to change some of their personal info in a db. I want to use a detailsview control for this. How can I get the detailsview to only pull up the record...
3
by: RR | last post by:
I have a button on a form (form A) that opens another form. The form that opens (form B) has a listbox that is populated with a call to a function in the "on current" event. When form B with the...
2
by: MLH | last post by:
Suppose that code running on FormB is moving the focus around on FormA to various textbox controls on FormA - Which form is the current form during this process? Is it FormA, which has the...
1
by: Peter Knörrich | last post by:
Hello, I've found another inconsistency, and looking through the list archives I can find mentions of funky stuff like print float('inf') giving Infanity
4
by: pamelafluente | last post by:
Hello. A question. It is possible to refer to the ID of an element within the element itself? And, if yes, what is the instruction or function. Example. Assume I have this: <div id="Square1" ...
8
by: Jeremy | last post by:
If we have a table with say 3 rows in it and one of the columns contains a checkbox such as <table> <tr> <td><input type="checkbox" name="ch_fld"></td> </tr> <tr> <td><input type="checkbox"...
3
by: Bob Cohen \(106531\) | last post by:
I want to define some metadata using custom attributes to apply to properties in various classes. The properties return values that are classes themselves. I want to retrieve the attribute...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.