I have been using C# for trying to parse a string into datetime format. It works as long as the string is not null but fails when its null. I used datetime.parse but it failed:
Datetime.parse:
Datetime ContactDate = DateTime.Parse((GetContactDateForClient(1)?.DisplayText)) -- (note: getcontactdateforclient.displaytext is one of my method which gets back date in string format)
Whenever my method gets back date as non null the above works great but if its null then my above line of code fails.
I tried datetime.tryparse but it shows me error during compilation ("Cannot convert System.Datetime ? to System.Datetime")
Datetime.TryParse:
DateTime value;
Datetime ContactDate = DateTime.TryParse((GetContactDateForClient(1)?.DisplayText), out value) ? value: (DateTime?) null;
Is it possible to assign 'ContactDate' value as null if the string is null and if not null then get the value as it comes back(GetContactDateForClient(1)?.DisplayText). Any pointer much appreciated.
DateTimechange it to typeDateTime?TryParse()instead then