Skip to content

Nullable reference type in explicit interface implementation, warning CS8618 #59879

Answered by ilbrando
ilbrando asked this question in Q&A
Discussion options

You must be logged in to vote

I found a work around. Using a private field.

public interface IFoo
{
  string Bar { get; set; }
}

public class FooExplicit : IFoo
{
  private readonly string _bar;
  public FooExplicit(string bar)
  {
    if (bar is null) throw new ArgumentNullException(nameof(bar));
    _bar = bar;
  }
  string IFoo.Bar => _bar;
}

Replies: 1 comment 11 replies

Comment options

You must be logged in to vote
11 replies
@CyrusNajmabadi
Comment options

@ilbrando
Comment options

@CyrusNajmabadi
Comment options

@ilbrando
Comment options

@CyrusNajmabadi
Comment options

Answer selected by ilbrando
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants