jjzjj

c# - 通用约束 : Can I test Equality of generic that can be a reference or value type?

我想要一个通用类,它可以接受引用类型或值类型,并且只执行基于相等性测试的操作。考虑以下几点:publicclassPropertywhereTProp:struct,IEquatable{publicTPropValue;publicvoidSetValue(ObservableObjectowner,TPropvalue){if(!Value.Equals(value))//cannotuse!=onstructconstrainedTProp{//...settheproperty}}}publicclassByRefPropertywhereTProp:class//Dontwa