c# - How to return the derived type from base method -


To better understand what I would like to do here:

  dog dog = Animal. Color ("red") claw (4). Bird bird = animal color blue"). Wing (1);   

I can do the following with the code given below:

  dog dog = animal. Pt. (4). Color ("red"); Bird bird = animal. Wing (1). Color ("blue");   

But I want to do it the first way.

Even my code is designed:

  public class animal {public static string color = ""; Public animal color (string _color) {color = _color; Turn it back. GetType (); }} Public Square Dog: Animals {Public stable human being pawNumber = 0; Public Static Dog Paw (Int'Pombery) {pawNumber = _pawNumber; This return; }} Public square bird: animal {public static wing number = 0; Public bird wing (int_vngnumber) {wingNumber = _wingNumber; This return; }}   

So, basically, this is not working because the color is typed in the form of a beast, even if I return it. GetType () (which gives me the correct type), is not return value

P> You can do this really ugly, but what do you ask.
  class program {static zero major (string [] args) {dog dog = new dog (). Color ("red"). ); Bird bird = new bird (). color blue"). Wing (1); }} Public abstract class animal {private string color = ""; Public animal color (string _color) {color = _color; This return; }} Public Abstract category ChainingAnimal & lt; T & gt; : Animals Where T: Animals {Public T Color (String _color) {Return (T) Base. Color (_color); }} Public square dog: Chenningemel & lt; Dogs & gt; {Private Ent pawNumber = 0; Public Dog Paw (int _pawNumber) {pawnumber = _pawNumber; This return; }} Public Class Bird: ChenningEnnamal & lt; Bird & gt; {Private int wing number = 0; Public bird wing (int_vngnumber) {wingNumber = _wingNumber; This return; }}    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -