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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:58:57+00:00 2026-06-14T06:58:57+00:00

I have an assembly compiled in VB.NET that contains two operators: Public Shared Operator

  • 0

I have an assembly compiled in VB.NET that contains two operators:

Public Shared Operator =(quarterA As CalendarQuarter, quarterB As CalendarQuarter) As Boolean
    Return quarterA.StartDate = quarterB.StartDate AndAlso
        quarterA.EndDate = quarterB.EndDate AndAlso
        quarterA.Quarter = quarterB.Quarter
End Operator

Public Shared Operator <>(quarterA As CalendarQuarter, quarterB As CalendarQuarter) As Boolean
    Return Not (quarterA = quarterB)
End Operator

However, when using the assembly in C# to perform equality checks if (qtr != null) I receive the error:

Cannot implicitly convert type 'object' to 'bool'

Usage in C# MVC4, Razor:

@{Html.BeginForm();}
    <div class="ui-form ui-form-horizontal form-width-narrow">
        <div class="title">
            Choose a Quarter</div>
        <div class="group">
            <label><strong>Control</strong></label>
            <div class="field">
                @Html.DropDownListFor(x => x.Quarter, new SelectList(Model.AvailableQuarters))
                <input value="Select" class="ui-button" type="submit" />
            </div>
        </div>
        @if (Model.Quarter != null) {
            // Error in the above statement 
        }           
    </div>
@{Html.EndForm();}

What do I need to do to make the equality operator behave properly?

  • 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-14T06:58:58+00:00Added an answer on June 14, 2026 at 6:58 am

    When I implement your code as-is and compare an instance to null I get a NullReferenceException in your equality operator. However if I add a null check it works fine:

    Public Shared Operator =(quarterA As CalendarQuarter, quarterB As CalendarQuarter) As Boolean
    
        If quarterA Is Nothing OrElse quarterB Is Nothing Then Return False
    
        Return quarterA.StartDate = quarterB.StartDate AndAlso
            quarterA.EndDate = quarterB.EndDate AndAlso
            quarterA.Quarter = quarterB.Quarter
    End Operator
    

    I suspect something else is causing the error you’re getting.

    Most likely you’re using the assignment operator (=) when you should be using the equality operator (==):

    if (qtr = null)   // wrong  - assigning null to qtr
    if (qtr == null)  // correct
    

    In addition, I would recommend overriding Equals and GetHashCode to be consistent with your equality operator.

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

Sidebar

Related Questions

I have a .NET assembly DLL that is created on-the-fly from pre-compiled code in
All, Lets say I have an assembly compiled under .NET 2.0. Can I run
I have a compiled .NET assembly with a specific resource file embedded (named 'Script.xml').
I have an assembly that contains an embedded resource. However, when this assembly is
I have a web solution that contains 5 class libraries and one asp.net web
I have the following setup: Main assembly that contains a WcfService and IWcfService contract.
It seems that if I have a .NET assembly that is going to be
I have a C# (2008/.NET 3.5) class library assembly that supports WPF (based on
I have a Windows service written in C#/.NET, compiled to AnyCPU, that dies on
I have a problem with Spark. I have compiled assembly with views, located in

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.