inheritance - Passing namespace in C# -
we have exercise inheritance in c#. problem put in question mark , in if statement know program passed person class or animal class or class under inventoryapplication namespace. :)
private void addbutton_click(object sender, eventargs e) { logic_layer.logic logic = new logic(); //logic.add<person>(); } namespace logic_layer { public class logic { public void add<inventoryapplication>() inventoryapplication : ? { //if { } } public void delete() { } public void edit() { } public void search() { } public void searchall() { } } }
you can't use such statement in constraint. however, later in method can this:
if (typeof(myobject).namespace == "inventoryapplication") { ... }
what better if classes want test (animal, person etc.) implement interface (say, imyinterface
).
for example:
void add<t>(<t> param) t : imyinterface {/*...*/}
Comments
Post a Comment