By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,423 Members | 1,327 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,423 IT Pros & Developers. It's quick & easy.

convert to Datetime array

P: 45
Hi All,

I have stringarray called Timesplit with time like(17:00-2:00).How to store Timeplit array values into datetime array value.I am having 7 values that's why i am using TimeIn[arrayIndex].I will increment arrayIndex for 7 times for 7 timeIn.

I am getting error while trying to store TimesPlit[0] to TimeIn[arrayIndex].I want 17:00 into TimeIn[arrayIndex] and 2:00 into TimeOut[arrayIndex].If i use datetime will get date also so please give me better options to store TimeIn and TimeOut.

Object reference error
Expand|Select|Wrap|Line Numbers
  1.    DateTime[] TimeOut = null;
  2.    TimeIn[arrayIndex]=Convert.ToDateTime(TimeSplit[0]); 
  3.    TimeOut[arrayIndex] = TimeSplit[1];
Sep 28 '10 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,731
You can access the Date or the Time portions of a DateTime Type.

As for the error you're's a Null Reference error ("Object reference Not set to an instance"). This occurs when you attempt to use an object that has not been initialized. In other words, the object is Null (or, in VB.NET, Nothing).

When you attempt to access a property or method of something that is Null or Nothing, you will get a Null Reference error.

In your case you are setting the TimeOut array to null and then a couple of lines latter you are trying to use it! Obviously this is going to cause a problem.

You should properly initialize the array before you use it:
Expand|Select|Wrap|Line Numbers
  1. DateTime[] TimeOut;
  2. TimeOut= new DateTime[7];
(You should do the same for the TimeIn array)

Sep 28 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.