Note that there are some explanatory texts on larger screens.

plurals
  1. POC# declare both, class and interface
    text
    copied!<pre><code>// interface public interface IHasLegs { ... } // base class public class Animal { ... } // derived classes of Animal public class Donkey : Animal, IHasLegs { ... } // with legs public class Lizard : Animal, IHasLegs { ... } // with legs public class Snake : Animal { ... } // without legs // other class with legs public class Table : IHasLegs { ... } public class CageWithAnimalsWithLegs { public List&lt;??&gt; animalsWithLegs { get; set; } } </code></pre> <p>What should I put in the ?? to force objects that inherit from both <code>Animal</code> and <code>IHasLegs</code>? I don't want to see a <code>Snake</code> in that cage neither a <code>Table</code>.</p> <p>-------------- EDIT --------------</p> <p>Thank you all for your answers, but here is the thing: What I actually want to do is this:</p> <pre><code>public interface IClonable { ... } public class MyTextBox : TextBox, IClonable { ... } public class MyComboBox : ComboBox, IClonable { ... } </code></pre> <p>TextBox/ComboBox is of course a Control. Now if I make an abstract class that inherits both Control and IClonable, I will loose the TextBox/ComboBox inheritance that I need. Multiple class inheritance is not allowed, so I have to work with interfaces. Now that I think of it again, I could create another interface that inherits from IClonable:</p> <pre><code>public interface IClonableControl : IClonable { ... } public class MyTextBox : TextBox, IClonableControl { ... } public class MyComboBox : ComboBox, IClonableControl { ... } </code></pre> <p>and then</p> <pre><code>List&lt;IClonableControl&gt; clonableControls; </code></pre> <p>Thank you!!</p>
 

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