相关疑难解决方法(0)

C#重载运算符==和!=

我遇到了从这几个类和接口中获得所需行为的问题.

这是我的问题,

//Inside a Unit Test that has access to internal methods and properties

INode  firstNode, secondNode;

INodeId  id = new NodeId (4);

first = new Node (id, "node");
second = new Node (id, "node");

Assert.IsTrue (first == second);
Run Code Online (Sandbox Code Playgroud)

上面的断言失败了,因为它似乎是在对象类的equals方法而不是Node和NodeId类中的重载运算符.

如果您对如何获得所需行为有任何建议,那将是非常棒的.

以下是我正在研究的框架的一部分:

public interface IIdentifier<T> where T : class
{
    TKeyDataType GetKey<TKeyDataType> ();

    bool Equals (IIdentifier<T> obj;
}

public interface INode
{
    string name
    {
        get;
    }

    INodeId id
    {
        get;
    }
}

public interface INodeId : IIdentifier<INode>
{
} …
Run Code Online (Sandbox Code Playgroud)

c# operator-overloading

3
推荐指数
1
解决办法
2687
查看次数

标签 统计

c# ×1

operator-overloading ×1