tubeshowcase●1,194,391 videos♡ My collection 0
← Learn to Code

Learn to Code05:38

C# interfaces 🐟

Bro Code ↗

From the creator

C# interfaces tutorial example explained #C# #interfaces #interface using System; namespace MyFirstProgram { class Program { static void Main(string[] args) { // interface = defines a "contract" that all the classes inheriting from should follow // An interface declares "what a class should have" // An inheriting class defines "how it should do it" // benefits = security + multiple inheritance + "plug-and-play" Rabbit rabbit = new Rabbit(); Hawk hawk = new Hawk(); Fish fish = new Fish(); rabbit.Flee(); hawk.Hunt(); fish.Flee(); fish.Hunt(); Console.ReadKey(); } interface IPrey { void Flee(); } interface IPredator { void Hunt(); } class Rabbit : IPrey { public void Flee() { Console.WriteLine("The rabbit runs away!"); } } class Hawk : IPredator { public void Hunt() { Console.WriteLine("The hawk is searching for food!"); } } class Fish : IPrey, IPredator { public void Flee() { Console.WriteLine("The fish swims away!"); } public void Hunt() {

Published 2021-07-03 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code