KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The following doesn't compile: public void MyMethod<T>(T value) { if (value == default(T)) { // do stuff } } Error: Operator '==' cannot be applied to operands of type 'T' and 'T' I can't use value == null because T may be a struct. I can't use value.Equals(default(T)) because value may be null . What is the proper way to test for equality to the default value?
Tags (comma-separated)
Save Edits
Cancel