Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
1.3 Basics: interfaces
//1.3 Interfaces using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //interface is a declaration of a contract, i.e. if interface does A() //and I give you an object that implements this interface //then this object must also do A() //This way you can write code that takes not concrete types, but interfaces //And then supply it any type that satisfies this interface ConcertArena concert = new ConcertArena(); concert.PerformConcert(new List<ISinging>(){new RobbieWilliams(), new SnoopLion()}); //concert.PerformConcert(new List<ISinging>(){new JamesBond()}); //JamesBond can't sing } } public class ConcertArena { public void PerformConcert(List<ISinging> artists) { foreach(ISinging a in artists) { a.Sing(); } } } public interface ISinging { void Sing(); } public class RobbieWilliams : ISinging { public void Sing() { Console.WriteLine("♪♪♪ robbie williams sings ♪♪♪"); } } public class SnoopLion : ISinging { public void Sing() { Console.WriteLine("♪♪♪ snoop lion sings ♪♪♪"); } } public class JamesBond { public void Sing() { Console.WriteLine("Daniel Craig tries to sing, but well ..."); } } }
run
|
edit
|
history
|
help
0
Main4
Left circular rotation of an array
dsdsdsdsd
database interior 0.2
Working with Strings
Found many section of times intersect.
linked list (add to end and beginning, and looking for cycles based on Floyd's algorithm)
Linear search
Does string contain only digits
project euler 17, C#