Click here to Skip to main content
13,196,730 members (73,285 online)
Rate this:
Please Sign up or sign in to vote.
See more:
If I write this code then it shows error :
But the following does not show any error :
DateTime Date=DateTime.Parse(DTLocal.Rows[0]["Date"].ToString());
Please explain what is the reason for such conversion.
Posted 27-Apr-13 19:40pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You have not told us the error you got, but I am pretty sure it is a compile time one, since TryParse is expecting a second out bound parameter (see:[^]).
The difference is there in on the msdn manual page:
The DateTime.TryParse(String, DateTime) method is similar to the DateTime.Parse(String) method, except that the TryParse(String, DateTime) method does not throw an exception if the conversion fails.
See this short sample code:
DateTime theDT1;
bool result1 = DateTime.TryParse("2013.01.01", out theDT1); // date is converted, resutl is true
DateTime theDT2;
bool result2 = DateTime.TryParse("not a date", out theDT2); // date is not converted, result is false
DateTime theDT3 = DateTime.Parse("not a date"); // date is not converted, exception thrown
Mohi Uddin Sumon 28-Apr-13 2:11am
Thank you Mr.Zoltán Zörgő for your kind response
Zoltán Zörgő 28-Apr-13 2:16am
You are welcome. If you found my answer helpful, feel free to accept it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171019.1 | Last Updated 28 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100