" method I am us...">

The type "MyObject" must be an unimaginable value type in order to use it as the "T" parameter in the generic type or "Nullable <T>" method

I am using .net framework 4.5

I get the following error

Error CS0453 The type "MyObject" must be an unimaginable value type in order to use it as the "T" parameter in the generic type or "Nullable" method

  public async Task<Nullable<MyObject>> MyMethod(string myParamter) {} 

I also tried

  public async Task<MyObject?> MyMethod(string myParamter) {} 

If I set the value as nullable, then why am I getting a red string under the method name with this error message

The stackflowflow answer package is simple, make the return type null, but for me, Visual Studio does not allow it.

+5
source share
1 answer

Since MyObject is an object, and objects are, by definition, nullable, does it make sense to use the Nullable<T> struct operator or ? to support null values.

Nullable<T> is for structures (e.g. DateTime ) and value types like int , float , etc.

+11
source

Source: https://habr.com/ru/post/1243923/


All Articles