相关疑难解决方法(0)

使用==比较两个结构

我试图在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)

c# struct equality

48
推荐指数
3
解决办法
5万
查看次数

如何检查结构是否已实例化?

我有一个结构(为了这个问题的目的)几乎模仿内置Point类型.

我需要在使用之前检查它是否已经实例化.什么时候Point,我可以这样做:

if (this.p == null)
Run Code Online (Sandbox Code Playgroud)

但现在生成以下错误:

运算符'=='不能应用于'ProportionPoint'和'<null>类型的操作数

如何将我的结构与null进行比较?还有另一种检查实例化的方法吗?

c# null struct

27
推荐指数
4
解决办法
4万
查看次数

标签 统计

c# ×2

struct ×2

equality ×1

null ×1