Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Returning Null Generic Type

$
0
0

I have a class:

public interface IA{    TValue? GetValue<TValue>();}public class A : IA{   public TValue? GetValue<TValue>()   {      ...      if (value is not null)                  return (TValue)value;      return default(TValue);   }}

This is alright, but when I try to implement the interface explicitly:

public interface IA{    TValue? GetValue<TValue>();}public class A : IA{   TValue? IA.GetValue<TValue>()   {      ...      if (value is not null)                  return (TValue)value;      return default(TValue);   }}

The compiler throws an error:

Cannot implicitly convert type TValue to TValue?

Is there a difference when implementing an interface explicitly? This seems to only be the case when dealing with a nullable generic return type.

Is this a bug or am I missing something?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>