0

Please correct my code:

j.PrDateTime = string.Empty(t.PrDT)
    ? "NULL"
    : DateTimeOffset.ParseExact(t.PrDT, "s", CultureInfo.InvariantCulture);

PrDateTime is nullable in db, t.PrDT is a string which might be empty.

2
  • use null instead of "NULL" Commented Dec 13, 2012 at 20:27
  • 1
    @Love Yes. One is a null reference and the other is a string literal. Commented Dec 13, 2012 at 20:30

1 Answer 1

3

I believe you want:

j.PrDateTime = string.IsNullOrEmpty(t.PrDT)
    ? (DateTimeOffset?)null
    : DateTimeOffset.ParseExact(t.PrDT, "s", CultureInfo.InvariantCulture);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.