Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7602251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:21:55+00:00 2026-05-30T23:21:55+00:00

new to C# so I’m having an issue with a short-hand statement. I want

  • 0

new to C# so I’m having an issue with a short-hand statement. I want to convert…

if (m_dtLastLogin == null)
    drow["LastLogin"] = DBNull.Value;
else
    drow["LastLogin"] = m_dtLastLogin;

to

drow["LastLogin"] = (m_dtLastLogin == null) ? System.DBNull.Value : m_dtLastLogin;

The long-hand version works great, however, the short-hand version generates the error “Type of conditional cannot be determined because there is no implicit conversion between ‘System.DBNull’ and ‘System.DateTime?'”. My supporting code is basically…

private DateTime? m_dtLastLogin;
m_dtLastLogin = null;
DataRow drow;
drow = m_oDS.Tables["Users"].Rows[0];

Can someone help me with the short-hand here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:21:56+00:00Added an answer on May 30, 2026 at 11:21 pm

    Well, the error message is pretty clear. The compiler needs to determine the type of the whole x?y:z expression. If y and z have the same type, it’s easy. If y is convertible to z, the type of the expression is that of z, likewise if z is convertible to y the type is that of y.

    In your case the type of y is DBNull, the type of y is the type of m_dtLastLogin (probably a datetime). Those two types cannot be converted into each other and have no common base type (except for Object), so the compiler doesn’t know what to do.

    You can help the compiler, however, by casting either y or z to object:

    drow["LastLogin"] = (m_dtLastLogin == null) ? (object)System.DBNull.Value : m_dtLastLogin;
    

    or

    drow["LastLogin"] = (m_dtLastLogin == null) ? System.DBNull.Value : (object)m_dtLastLogin;
    

    This way the whole expression has the type object, which can then be assigned to drow["LastLogin"].

    Reference:
    C# language specification – http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf

    Section 14.13, Conditional operator

    Quote

    The second and third operands of the ?: operator control the type of the conditional expression. Let X and Y be the types of the second and third operands. Then,

    • If X and Y are the same type, then this is the type of the conditional expression.

    • Otherwise, if an implicit conversion (§13.1) exists from X to Y, but not from Y to X, then Y is the type of the conditional expression.

    • Otherwise, if an implicit conversion (§13.1) exists from Y to X, but not from X to Y, then X is the type of the conditional expression.

    • Otherwise, no expression type can be determined, and a compile-time error occurs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to javascript/jquery and having a hard time with using this or $(this) to
I want use html5's new tag to play a wav file (currently only supported
New with jQuery. Here's what I have so far - basically, I want jQuery+ajax
New to PostgreSQL (and only 6 months more experienced in programming in general), having
New to Applets, I have never dealt with having to export the resources to
new to Django, and encountering a strange issue: Firefox runs completely well with the
New to Rails... here goes: If I want my 'create' method to respond differently
New to Objective-C and iOS development, would love a hand here! I have written
New to Objective-C, Cocoa, and compiled languages in general so forgive my ignorance: UIImage
New to node. Can somebody help me understand how to use/configure r.js with coffeescript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.