0

Possible Duplicate:
Nullable type as a generic parameter possible?
Is creating a C# generic method that accepts (nullable) value type and reference type possible?

In c# I would like to restrict my generic method to accept only nullable types. Is that possible?

public T Method<T>() where T : somesortofnullablerestriction
{
   ...
}
Community
  • 1
  • 1
Jesper Kihlberg
  • 546
  • 1
  • 4
  • 16
  • 1
    see also http://stackoverflow.com/questions/4003026/is-creating-a-c-generic-method-that-accepts-nullable-value-type-and-reference and http://stackoverflow.com/questions/303287/can-a-generic-method-handle-both-reference-and-nullable-value-types – Ian Ringrose Sep 07 '11 at 10:26
  • http://stackoverflow.com/questions/209160/nullable-type-as-a-generic-parameter-possible – Ray Sep 07 '11 at 10:36
  • That solution is not valid in my case, I don´t wan´t to restrict to struct. – Jesper Kihlberg Sep 07 '11 at 11:05

1 Answers1

1

You can do this.

public Nullable<T> Method<T>()
{
}
Ray
  • 45,695
  • 27
  • 126
  • 169