KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Possible Duplicate: Can’t operator == be applied to generic types in C#? I've got the following generic class and the compiler complains that " Operator '!=' cannot be applied to operands of type 'TValue' and 'TValue' " (see CS0019 ): public class Example<TValue> { private TValue _value; public TValue Value { get { return _value; } set { if (_value != value) // <<-- ERROR { _value= value; OnPropertyChanged("Value"); } } } } If I constrain TValue to class , I could use Object.Equals() . Since I need this for boths structs and classes I'd be very happy if I could avoid that though. So the question is, how can I compare two elements of the same but unconstrained generic type for equality?
Tags (comma-separated)
Save Edits
Cancel