我试图在C#中使用equals(==)比较两个结构.我的结构如下:
public struct CisSettings : IEquatable<CisSettings>
{
public int Gain { get; private set; }
public int Offset { get; private set; }
public int Bright { get; private set; }
public int Contrast { get; private set; }
public CisSettings(int gain, int offset, int bright, int contrast) : this()
{
Gain = gain;
Offset = offset;
Bright = bright;
Contrast = contrast;
}
public bool Equals(CisSettings other)
{
return Equals(other, this);
}
public override bool Equals(object obj)
{
if …Run Code Online (Sandbox Code Playgroud) 我有一个结构(为了这个问题的目的)几乎模仿内置Point类型.
我需要在使用之前检查它是否已经实例化.什么时候Point,我可以这样做:
if (this.p == null)
Run Code Online (Sandbox Code Playgroud)
但现在生成以下错误:
运算符'=='不能应用于'ProportionPoint'和'<null>类型的操作数
如何将我的结构与null进行比较?还有另一种检查实例化的方法吗?