1 Replies - 452 Views - Last Post: 04 November 2010 - 01:14 AM Rate Topic: -----

#1 Nomanirvana  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 47
  • Joined: 06-October 10

Overloading the equality operator

Posted 04 November 2010 - 12:22 AM

Anyone know if it is possible to overload the == operator in such a way that you could check for equality with any element in an array of elements?

For instance,


if (input == ( element1, element2, element3, etc.)
{
     // DO SOMETHING
}

or even

if (input == (string[] array)
{
    // DO SOMETHING
}



Doesn't seem to be too much around on this topic, anyone have an idea?

Is This A Good Question/Topic? 0
  • +

Replies To: Overloading the equality operator

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Overloading the equality operator

Posted 04 November 2010 - 01:14 AM

If the type input is of a class you defined you can overload the == operator to do that.
If it isn't then without the language supporting custom operators the best you can do is to implement an extension method. See insertAlias's Blog Post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1