0

I wanted to check out new feature of C#8, default implementation of interface. For this I created simple code:

class Program
{
    static void Main(string[] args)
    {
        var test = new ConsoleLogger();
        test.Send("test");
    }
}
public interface ILogger
{
    void Send(string text) => Console.WriteLine(text);
}

public class ConsoleLogger : ILogger
{
}

On compilation and in Visual Studio on line with test.Send("test") I get error:

'ConsoleLogger' does not contain a definition for 'Send' and no accessible extension method 'Send' accepting a first argument of type 'ConsoleLogger' could be found (are you missing a using directive or an assembly reference?)

I don't get any errors in interface, so version of netcore is correct/im using c#8. Do you know how can I get it to work?

I'm using core SDK 3.1.201

Maciejowski
  • 11
  • 1
  • 1
  • 3

1 Answers1

0

Ok, I found out what was the problem. You can't use var, you have to make it ILogger test = new ConsoleLogger();

Maciejowski
  • 11
  • 1
  • 1
  • 3