473,323 Members | 1,551 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,323 software developers and data experts.

Simple array problem

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[i]? Now I'm doing try { }
catch for null references, but there must be a normal way of checking
for that...

Nov 17 '05 #1
2 3537
Try this:

if (addrs[i] == null)
{
// addrs[i] element is null
}

"Viraptor" <vi******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
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[i]? Now I'm doing try { }
catch for null references, but there must be a normal way of checking
for that...
Nov 17 '05 #2
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


"Viraptor" wrote:
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[i]? Now I'm doing try { }
catch for null references, but there must be a normal way of checking
for that...

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Mateer | last post by:
Hi Why does the following code allow me to keep the same session when in the same sub domain (ie admin.localhost), yet not when I goto another related domain eg main.localhost? I would like...
4
by: Owen Parker | last post by:
Hi all I am not a java programmer but i can hack at it a bit. I am trying to allow a user to define the text in a simple javascript text scroller. The data is stored as multiple records in a...
6
by: hoover_richard | last post by:
I am a newbie to C++ and I need help with a simple program I am trying to write. My program is designed to print all of the odd integers contained in an array and output the sum of the odd...
0
by: romain.jouin | last post by:
hi ! I'm trying to simulate a "windows explorer-like" tree on my page. What I would like is when the user click one of the level, the data make themselves visible ( It's ok to recharge the...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
5
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as...
51
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
27
by: karan.shashi | last post by:
Hey all, I was asked this question in an interview recently: Suppose you have the method signature bool MyPairSum(int array, int sum) the array has all unique values (no repeats), your...
18
by: Bob Cummings | last post by:
Not sure if this is the correct place or not. Anyhow in school we were taught that when trying to calculate the efficiency of an algorithm to focus on something called FLOPs or Floating Point...
1
by: Ironroot | last post by:
Hi all Ok in class to do we had to do the following and I keep on running into the same problem: class Array { public: Array(int size); //constructor - sets capacity to size void...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.