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

CsharpProgrammingServer Side Programming

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
}
raja
Published on 16-Aug-2018 12:18:39
Advertisements