Equality of two structs in C#

前端 未结 6 856
独厮守ぢ
独厮守ぢ 2020-12-17 21:15

I look for an equality between two instances of this struct.

public struct Serie
{
    T[]         X; 
    double[]    Y;

    public Serie(T[] x, d         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 21:51

    The part s1.Y == s2.Y tests if they are 2 references to the same array instance, not if the contents are equal. So despite the title, this question is actually about equality between array(-reference)s.

    Some additional advice: Since you are overloading you should design Serie<> as immutable and because of the embedded array I would make it a class instead of a struct.

提交回复
热议问题