Why do I get an error instantiating an interface?

后端 未结 6 1086
生来不讨喜
生来不讨喜 2020-12-08 06:22

I have a class and an interface, and when I try to instantiate the interface, I get an error:

Cannot create an instance of the abstract class or inter

6条回答
  •  余生分开走
    2020-12-08 06:50

    You cannot instantiate an abstract class or interface. You must inherit it, if its an abstract class, or implement it if it's an interface. e.g.

    ...
    private class User : IUser
    {
      ...
    }
    
    User u = new User();
    

提交回复
热议问题