If I have a DateTime, and I do :
date.Year.ToString()
I get the Year as String. But Also if I do
date.Year + ""
the differences is only that the second one doesnt get an exception if there isn’t the Date? (which i prefeer)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Won’t work if date is null.
Works even if year is null as binary + operator substitutes null with a empty string.
This is what MSDN says about binary + operator concatenating two strings:
The binary + operator performs string concatenation when one or both operands are of type string. If an operand of string concatenation is null, an empty string is substituted. Otherwise, any non-string argument is converted to its string representation by invoking the virtual ToString method inherited from type object. If ToString returns null, an empty string is substituted.
More information on http://msdn.microsoft.com/en-us/library/aa691375%28VS.71%29.aspx