Simple array problem

  • Thread starter Thread starter Viraptor
  • Start date Start date
V

Viraptor

Hello
I'm new to c#. I've got arrays in a class:
private DateTime[] dates;
private IPAddress[] addrs;
In constructor:
dates = new DateTime[5]; addrs = new IPAddress[5];
I'm adding some data to it like this:
dates[0]=...; addrs[0]=...; Array.Sort(dates, addrs);
How can I say if there is anything in addrs? Now I'm doing try { }
catch for null references, but there must be a normal way of checking
for that...
 
Try this:

if (addrs == null)
{
// addrs element is null
}

Hello
I'm new to c#. I've got arrays in a class:
private DateTime[] dates;
private IPAddress[] addrs;
In constructor:
dates = new DateTime[5]; addrs = new IPAddress[5];
I'm adding some data to it like this:
dates[0]=...; addrs[0]=...; Array.Sort(dates, addrs);
How can I say if there is anything in addrs? Now I'm doing try { }
catch for null references, but there must be a normal way of checking
for that...
 
For the array of DateTime you can check to see if the element of the array is
equal to DateTime.MinValue which is the value assigned to the DateTime when
it is initialized.

For the IPAddress you can check for null since the IPAddress is a reference
type.

Hope that helps
Mark R Dawson
http://www.markdawson.org
 
Back
Top