What is the difference between an interface and a class in C#?


An interface is a class without fields or method implementation. It cannot implement the methods it defines.

A class generally implements the methods defined in an interface.

Interface

Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members.

public interface interface_name {
   // interface_members
}

Class

Class is a blueprint for a data type. This does not actually define any data, but it does define what the class name means. That is, what an object of the class consists of and what operations can be performed on that object.

class class_name {
   // class_members
}

Updated on: 21-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements