public string DescribeInteraction(IObjectInSpace other) { // Use if/else and instanceof to avoid hardcoded class names switch (other.GetType().ToString()) { case "Planet": return DescribeInteraction((Planet)other); case "Asteroid": return DescribeInteraction((Asteroid)other); default: return "the " + Name + " interacts with something. the outcome is unkown."; } }
public string DescribeInteraction(IObjectInSpace other) { // Use if/else and instanceof to avoid hardcoded class names switch (other.GetType().ToString()) { case "Planet": return(DescribeInteraction((Planet)other)); case "Asteroid": return(DescribeInteraction((Asteroid)other)); default: return("the " + Name + " interacts with something. the outcome is unkown."); } }
public string DescribeInteraction(IObjectInSpace other) { return "the " + Name + " interacts with something. the outcome is unkown."; }
public string DescribeInteraction(IObjectInSpace other) { // The following does work because the dynamic type gets resolved during runtime return this.DescribeInteraction((dynamic)other); }
public string DescribeInteraction(IObjectInSpace other) { // At this stage we don't know what other is but we know that this is a SpaceShip return(other.DescribeInteractionWithSpaceShip(this)); }
public string DescribeInteraction(IObjectInSpace other) { // At this stage we don't know what other is but we know that this is a SpaceShip return other.DescribeInteractionWithSpaceShip(this); }
public string DescribeInteraction(IObjectInSpace other) { // The following does work because the dynamic type gets resolved during runtime return(this.DescribeInteraction((dynamic)other)); }
public string DescribeInteraction(IObjectInSpace other) { return("the " + Name + " interacts with something. the outcome is unkown."); }