Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
If I write this code then it shows error :
DateTime.TryParse(DTLocal.Rows[0]["Date"].ToString())
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 20:40pm

1 solution

Rate this: bad
good
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: http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx[^]).
The difference is there in on the msdn manual page:
Quote:
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
  Permalink  
Comments
Mohi Uddin Sumon at 28-Apr-13 2:11am
   
Thank you Mr.Zoltán Zörgő for your kind response
Zoltán Zörgő at 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
0 OriginalGriff 280
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 120
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 28 Apr 2013
Copyright © CodeProject, 1999-2014
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