C#: Trying to invoke a method in a class -


i programming game. each level has class (level1, level2, etc) tells game objects set plus other stuff. each level shares interface ilevel.

all objects in scene have access in ilevel, want call method exists in specific level class.

for example:

public class level1, ilevel {     public int getanumber() {        return 5;     } } 

the calling class needs this:

public class someobject {     ilevel mylevel = new ilevel();     int x = ... // need call getanumber() without knowing object level1, level2, etc. } 

i believe need use invoke somehow, wasn't able work. read documentation on msdn still wasn't able work.

thank help!

here either u can use if condition is , as operators or make ilevel abstract class getnumber returning negative values default.

public class someobject {     ilevel mylevel = new ilevel();     int x = -1;      if(mylevel level1) {         x = (mylevel level1).getanumber();     } } 

or

public abstract class ilevel {     public virtual int getanumber() {         return -1;     } }  public class level1 : ilevel {     public override int getanumber() {        return 5;     } } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -