Abhilash J A

Abhilash J A

  • 530
  • 2.4k
  • 600.5k

C# - If datetime return null show 'Unknown' message.

Dec 8 2016 10:16 AM
Hello everyone,
 
I have datatable that contain data like this
 
  1. public Nullable<DateTime> LogInTime { getset; }  
  2.       public Nullable<DateTime> LogOutTime { getset; }  
  1. LogInTime = m.Field<DateTime?>("LogInTime"),  
  2.                   LogOutTime = m.Field<DateTime?>("LogOutTime")  
 
And here I have a Linq query for, if LogOutTime is existing null return 'Unknown' message.
 
  1. var logOutDate = (from A in logList select (A.LogOutTime.ToString() ?? "Unknown").ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)).Distinct();  
 but getting empty string array in 'logOutDate' object.
 
How can I get Unknown messege if LogOutTime existing null value?
 

Answers (1)