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 8219569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:12:43+00:00 2026-06-07T13:12:43+00:00

Perhaps my Google-Fu has failed me, but I haven’t been able to determine if

  • 0

Perhaps my Google-Fu has failed me, but I haven’t been able to determine if comparing a nullable in .NET will always be less than something else.

I’ve got some code similar to this

MyClass findLatest(List<MyClass> items){
    DateTime? latest_tstamp = null;
    MyClass latest_item = null;
    foreach(var item in items){
        if (latest_tstamp < item.tstamp){
            latest_tstamp = item.tstamp;
            latest_item = item;
        }
    }
    return latest_item;
}

It’s seemed to work in the few limited cases I’ve tried (item.tstamp is declared DateTime? tstamp as well, of course).

Is this guaranteed behavior?

Conclusion(?)

Based on the answers (and Jon Skeet’s [answer on another question]), I’ve gone with the following check:

if (item.tstamp != null &&
    (latest_tstamp == null || latest_tstamp < item.tstamp)){
    // do stuff
}
  • 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-06-07T13:12:44+00:00Added an answer on June 7, 2026 at 1:12 pm

    This is behavior is guaranteed by the C# specification. The result of < on nullable value-types is false if any of them is null. Reference types on the other hand might exhibit different behavior.

    Still I wouldn’t recommend using this. It’s hard to understand this code. I’d prefer an explicit null check, or just a boolean flag isFirstElement instead of using a nullable in the first place.

    7.2.7 Lifted operators

    Lifted operators permit predefined and user-defined operators that operate on non-nullable value types to also be used with nullable forms of those types. Lifted operators are constructed from predefined and user-defined operators that meet certain requirements, as described in the following:

    …

    • For the relational operators
           <   >   <=   >=
      a lifted form of an operator exists if the operand types are both non-nullable value types and if the result type is bool. The lifted form is constructed by adding a single ? modifier to each operand type. The lifted operator produces the value false if one or both operands are null. Otherwise, the lifted operator unwraps the operands and applies the underlying operator to produce the bool result.

    (Quoted from C# Language Specification Version 3.0)

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

Sidebar

Related Questions

This question perhaps has been answered earlier, but I did not see an answer.
Perhaps, you know that google image search by local image file .. But, Google
Perhaps I'm at a misunderstanding in architecture - but if a machine has, say,
Perhaps I'm just not using the right Google-age. But I am trying to remember
I've done my SO and Google research, and haven't found anyone who has tackled
I've been using http://code.google.com/p/phpbrowscap/ for a project, and it usually works nice. But a
Google Translate has a developer tool that will enable google translate on a website.
I'm sure this has been asked before, but I have no idea what it
Perhaps a silly question, but though google returned lots of similar cases, I could
I'm looking for a mapping API something which has similar functionality to Google-maps but

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.