5
Reply

C# linq nullable object

dc

dc

11 years ago
3.6k
In a C# 2008 application, I am using linq to sql to connect to a sql server 2008 r2 database. One of the linq statements returns the value to a datetime field called startdate.
My first if test looks like
 if (startdate != null).

 When there is nothing returned from the linq query and the code is on the statement,
(startdate != null), the program then lands on the catch statement of a try catch block.

Thus can you tell me what I can do so the the application does not land on the catch block code with an exception. I would think there is a way to obtain the datetime value when nothing is returned.
Can you show me what code solves the problem and explain how it solves the problem?


Answers (5)