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

  • Home
  • SEARCH
  • 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 4084130
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:24:01+00:00 2026-05-20T18:24:01+00:00

While writing this method for a custom NUnit Constraint. private void AddMatchFailure<TExpected, TActual>(string failureName,

  • 0

While writing this method for a custom NUnit Constraint.

    private void AddMatchFailure<TExpected, TActual>(string failureName, TExpected expected, TActual actual)
    {
        _matchFailures.Add(
            String.Format(MatchFailureFormat, failureName,
            (expected == null) ? "null" : expected.ToString(),
            (actual == null) ? "null" : actual.ToString()));
    }

Resharper warns that expected and actual might be ValueType objects.

e.g. TExpected is DateTime
   expected == null;//  but DateTime is a struct.

What are the rules when comparing a ValueType to null and how should I write the method to account for that without limiting the generic parameters by adding a class constraint?

  • 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-20T18:24:02+00:00Added an answer on May 20, 2026 at 6:24 pm

    Don’t change the code – just ignore the warning. If the type parameter is a non-nullable value type, the comparison will always fail and it’ll always call ToString() instead. I don’t know whether it’s actually JITted away, but I wouldn’t be surprised… and this doesn’t sound like it’s performance-critical code anyway 🙂

    I’d personally leave the warning “on”, but ignore it in this particular case – possibly with a comment.

    I think I came across the same warning a few times when reimplementing LINQ to Objects.

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

Sidebar

Related Questions

I'm writing a cache-eject method that essentially looks like this: while ( myHashSet.Count >
I'm writing a program that uses java.net.URLDecoder.decode(String value, String encoding) . Apparently, this method
I've run into this while writing a Traveling Salesman program. For an inner loop,
I got this doubt while writing some code. Is 'bool' a basic datatype defined
This popped-up while writing a script for vim. Using the well-documented ':normal' command: :normal
I'm writing some code that looks like this: while(true) { switch(msg->state) { case MSGTYPE:
I find myself writing code that looks like this a lot: set<int> affected_items; while
While striving for const-correctness, I often find myself writing code such as this class
Writing a python program, and I came up with this error while using the
While writing and testing a python method, I am currently using the following approach:

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.