i have two numbers in array list
array[0] = 1
array[1] = 2
but
if i use array[2] i know its null not exist but how to check
if( array[2] what can i do for check or exist )
{
show( array not exit);
}
plz help.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jun 13, 2012, 11:14 AM
SaqiPosted Jun 13, 2012, 11:18 AM
SaqiPosted Jun 13, 2012, 11:05 AM
if (ldays >= 31)
{
Double t = ldays / 30;
char[] s = { '.' };
String[] lastmonth = t.ToString().Split(s);
hipertensos.idade_txb.Text = "";
string months = lastmonth[0].ToString();
string days = null;
if (Convert.ToInt32(lastmonth[1]) > lastmonth.Length ) error is there some time lastmonth[1] not exist sometime have value.......................
{
days = lastmonth[1].ToString();
}
else
{
days = "0";
}
hipertensos.idade_txb.Text = String.Format("{0:0}.{1:0}.{2:0}", years[0], months, days);
}
else
{
hipertensos.idade_txb.Text = String.Format("{0:0}.{1:0}.{2:0}", years[0], "0", idays );
}
Glenn PattonPosted Jun 13, 2012, 11:02 AM
Glenn PattonPosted Jun 13, 2012, 11:00 AM
Silly kind of question if you only have two (0,1) elements in the array why are you looking at the third (2) why not limit the value to the max it can have in it in this case two,
so you have limit set to n-1, where n is the array size.
something like the following:
int limit_array = 0;
limit_arrray = array.GetLength();
for(int i = 0; i <= limit_array; i++)
{
}
By keeping to the size of the array you won't need to venture into try....catch() land which can be painful!
VulpesPosted Jun 13, 2012, 10:56 AM
if (array.Count > 2 && array[2] == null)
{
// do something
}
SaqiPosted Jun 13, 2012, 10:52 AM
thanks
VulpesPosted Jun 13, 2012, 10:48 AM
if (array.Count > 2)
{
// do something with array[2]
}
Notice that array[2] can still exist but can have a value of null. You need to check for nullness separately.