Tutorial by Examples

An interface is used to enforce the presence of a method in any class that 'implements' it. The interface is defined with the keyword interface and a class can 'implement' it by adding : InterfaceName after the class name. A class can implement multiple interfaces by separating each interface with ...
public interface IAnimal { string Name { get; set; } } public interface INoiseMaker { string MakeNoise(); } public class Cat : IAnimal, INoiseMaker { public Cat() { Name = "Cat"; } public string Name { get; set; } public string M...
Explicit interface implementation is necessary when you implement multiple interfaces who define a common method, but different implementations are required depending on which interface is being used to call the method (note that you don't need explicit implementations if multiple interfaces share t...
An interface is a definition of a contract between the user of the interface and the class that implement it. One way to think of an interface is as a declaration that an object can perform certain functions. Let's say that we define an interface IShape to represent different type of shapes, we exp...
An Interface's function known as a "contract" of functionality. It means that it declares properties and methods but it doesn't implement them. So unlike classes Interfaces: Can't be instantiated Can't have any functionality Can only contain methods * (Properties and Events are metho...
Don't you hate it when interfaces pollute you class with too many members you don't even care about? Well I got a solution! Explicit Implementations public interface IMessageService { void OnMessageRecieve(); void SendMessage(); string Result { get; set; } int Encoding { get; se...
Interfaces can seem abstract until you seem them in practice. The IComparable and IComparable<T> are great examples of why interfaces can be helpful to us. Let's say that in a program for a online store, we have a variety of items you can buy. Each item has a name, an ID number, and a price. ...

Page 1 of 1