Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - Interface -Help in power of Interface
    primarykey
    data
    text
    <p>I am new to C#. Recently I have read an article.It suggests </p> <p><b></p> <p><i> "One of the practical uses of interface is, when an interface reference is created that can </p> <p>work on different kinds of objects which implements that interface." </i></p> <p></b></p> <p><i> Base on that I tested (I am not sure my understanding is correct) </i></p> <pre><code> namespace InterfaceExample { public interface IRide { void Ride(); } abstract class Animal { private string _classification; public string Classification { set { _classification = value;} get { return _classification;} } public Animal(){} public Animal(string _classification) { this._classification = _classification; } } class Elephant:Animal,IRide { public Elephant(){} public Elephant(string _majorClass):base(_majorClass) { } public void Ride() { Console.WriteLine("Elephant can ride 34KPM"); } } class Horse:Animal,IRide { public Horse(){} public Horse(string _majorClass):base(_majorClass) { } public void Ride() { Console.WriteLine("Horse can ride 110 KPH"); } } class Test { static void Main() { Elephant bully = new Elephant("Vertebrata"); Horse lina = new Horse("Vertebrata"); IRide[] riders = {bully,lina}; foreach(IRide rider in riders) { rider.Ride(); } Console.ReadKey(true); } } } </code></pre> <hr/> <p>Questions :</p> <p></p> <p><li> Beyond such extend, what are the different way can we leverage the elegance of Interfaces ?</p> <p></li></p> <p><li> What is the Key point that I can say this can be only done by interface (apart from </p> <p>multiple inheritances) ?</p> <p></li></p> <p></p> <p><b></p> <p>(I wish to gather the information from experienced hands).</p> <p></b></p> <p>Edit :</p> <p>Edited to be concept centric,i guess.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload