Object reference not set to an instance problem

  • Thread starter Thread starter Abdessamad Belangour
  • Start date Start date
A

Abdessamad Belangour

Hi,
I have a method to sort an array.
The sort method header is :

private void sort(ref string[] t)
{
string c;
if (t.Length>0)
{.....}
}

I call it as follow : sort(ref myArray);
Is there any error in that?
thanks.
 
Hi,

Abdessamad Belangour said:
Hi,
I have a method to sort an array.
The sort method header is :

private void sort(ref string[] t)
{
string c;
if (t.Length>0)
{.....}
}

I call it as follow : sort(ref myArray);
Is there any error in that?
thanks.


myArray could be null.
The error will be thrown in if (t.Length>0) line.
You might change the line to:
if (t != null && t.Length>0)

And, btw, you don't need to pass myArray as ref (your are dealing with its
elements).
 
Back
Top