What is the difference between following declarations:

WebUserService.Service.IUserService userService = new WebUserService.Service.UserService();
WebUserService.Service.UserService userService = new WebUserService.Service.UserService();

I want to know the difference in usage and the the one that is most efficient in terms of programming in C#.

Recommended Answers

All 2 Replies

The only difference is that you are holding on to a reference of the interface versus the class. The class implements more functionality than the interface but you can also cast the interface reference to the class and still call any method. As far as efficiency there is no difference. Both lines are instantiating a UserService .

thanks sknake

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.