Jump to content

Recommended Posts

Posted

Is there a way of asking Visual Studio to create an equivilence operator for structs and/or classes such that == is defined as all of it's elements being equivilent.

 

Have an example:

 

class ComplexNumber {

* private int re,im;

}

 

and ask VS to derive the equivilence relation:

 

public static bool operator== (ComplexNumber a, ComplexNumber b){

* return a.re == b.re && a.im == b.im;

}

 

 

but for much larger numbers of fields (say 20+)?

 

Before anyone suggests it, I don't want to use reflection, and although I can type them in manually, it means that if fields are added to the class later then unless someone shrewdly adds said field into the == function, it might break the equivilence.

 

 

More...

 

View All Our Microsft Related Feeds

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...