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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:04:48+00:00 2026-05-10T17:04:48+00:00

Fixed: See notes at bottom I am implementing a generic class that supports two

  • 0

Fixed: See notes at bottom

I am implementing a generic class that supports two features, implicit type conversion and custom equality operators. Well, it supports IN-equality as well, if it does that.

1) if ( 'value' = myInstance ) then ... 2) Dim s As String = myInstance 3) Dim s As String = CType(myInstance,String) 

The problem I am having is that if I support #2, implicit conversion, then I can’t get my equality operators to work, since they complain about no conversion being the most specific.

The error I get is this (simplified a bit for brevity):

Overload resolution failed because no accessible '=' is most specific for these arguments:     'Public Shared Operator =(obj As MyClass, data As String) As Boolean': Not most specific.     'Public Shared Operator =(data As String, obj As MyClass) As Boolean': Not most specific.     'Public Shared Operator =(obj1 As MyClass, obj2 As MyClass) As Boolean': Not most specific. 

What is the best way of implementing this. Just as importantly, what should I leave out? I have implemented the following conversions

Operator =(ByVal data As String,    ByVal obj  As classType) As Boolean (and <>) Operator =(ByVal obj  As classType, byval data As String) As Boolean (and <>) Operator =(ByVal obj1 As classType, ByVal obj2 As classType) As Boolean (and <>) Equals(obj as Object) as Boolean Equals(compareTo as classType ) as Boolean Equals(compareTo as String) as Boolean Widening Operator CType(ByVal source As String) As classType Widening Operator CType(ByVal source As classType) as String Narrowing Operator CType(ByVal inst As classType) As dataType 

In my widening operator I do some reflection, which is why I wanted to be able to do an implicit convert DOWN to String when I do a comparison or assignment with the string on the left side.

A) SomeObject.StringPropertySetter = MyClass 

Fix (edit)

I went way overboard in what I implemented, because I didn’t understand what was happening. Comparison between the base types (ie string/double/guid) takes place via the widening ctype(…) as String (or Guid,etc) operator. In the end, i just implemented these functions and all my test cases still pass, in addition to assignment from the class to a base type instance

Public Class MyClass(Of BaseType)      Widening Operator CType(ByVal source As dataType) As MyClass      Widening Operator CType(ByVal source As MyClass) As dataType //conv between inst & base     Equals()  // for datatype, classType, object     Operator <>(MyClass,MyClass) // for comparison between two instances     Opeator   =(MyClass,MyClass)     

comments are c style, but code is vb.net

Of course the class is a little more complicated than that, but that give me everything I needed 🙂

  • 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. 2026-05-10T17:04:49+00:00Added an answer on May 10, 2026 at 5:04 pm

    You should not override the = operator. If you have implicit conversions to types such as string or int, then let the default equality operator take over.

    As a general rule, if you need to customize equality for a class you should override the Equals(object) method.

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

Sidebar

Ask A Question

Stats

  • Questions 86k
  • Answers 86k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Move the creation of the array into the __init__ method.… May 11, 2026 at 5:26 pm
  • Editorial Team
    Editorial Team added an answer You use the setImage: method, supplying it with an NSImage… May 11, 2026 at 5:26 pm
  • Editorial Team
    Editorial Team added an answer A good XSLT solution will map your human-readable rules to… May 11, 2026 at 5:26 pm

Related Questions

I'm working on a Facebook-like toolbar for my website. There's a part of the
EDIT : To people building tagging systems. Don't read this. It is not what
[Meta-note:] I was browsing the question page, getting really tired of DIVS vs Tables
I have implemented the MOD 10 check digit algorithm using SQL, for the US

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.