C# Overloading Operator == and != -
I am having trouble getting the desired behavior from some of these classes and interfaces.
Here's my problem,
// Insert the internal methods and properties inside the unit test, the inode first node, the second node; INodeId ID = New node ID (4); First = new node (id, "node"); Second = new node (id, "node"); Assign ISRU (first == seconds); The above is failing because it is going to be the method equivalent to the object class instead of overloaded operators in the node and noded classes. If you have
public interface iiDentifier & lt; T & gt; How can I get the desired behavior but any suggestions? Where T: Class {TKeyDataType GetKey & lt; TKeyDataType & gt; (); Public interface INodeId: IIdentifier & lt; INode & gt; {} Public square node: INode {INodeId ID, string} INODI {ID} name) {// Work} Public Static Bull Operator == (node N1, node N2) {Return N1. Angle (N2);} Public Static Bull Operator! = (Node n1, node n2) {returns! N1 Angle N2);} Public Child Eules (INLDOode) {this.name == node.name & amp; This.id = node.id;} #region INode Properties} Public Square NodeID: INOD ID {Internal Node ID (// work}} Public Static Bull Operator == (NodeID N1, NodeID N2) {Return N1 Angle (N2);} Public Static Bull Operator! = (NodeID N1, NodeID N2) {Return! N1 Angels (N2);} Public Override Bull Similar S (object obj) {Return it. Aquales ((IIDAntifier & Lt; IN & gt;) OBG); } Public Bull Eccles (IEDAntifier and LT; INDAG> OBG) {Reserve Obje. Gateke & Lt; At & G; () == This is Gateke Lieutenant; Int & G; (); } Public TKeyDataType GetKey & lt; TKeyDataType & gt; () Return {Return (TKDatype) Return Change Type (M_ID, Typef (TKDDtype), Culture Info. Inventive Culture); Private Ind M_ID; } Operator overload is resolved at the time of compilation, depending on the type of operation,
INode.operator == , not
node. Operator ==
. Since INode.operator ==
is not defined, the overload is resolved in the Object.operator ==
, which compares the context. There is no great way around it, the most correct thing is that instead of equal to
, ==
can be any kind of object . If in reality, actually a fake virtual operator overload is required, then you should define the operator ==
in the root code, which is the successor to your objects, and call that surcharge Equals
Note, however, this will not work for the interface, which you have.
Comments
Post a Comment