c# - How do i dynamically cast a child class from its parent class? -


What I'm trying to do here is that I have a class with the parentform one of its essentials Form has been added to the class with 2 things.

Then every and form I get it near ParentForm so I like

  class f1 : Parentform class F2: ParentForm class f3: ParentForm etc ...   

Now I say that I have both F1 and F2 A button is F3 and the F3 form constructor looks like this:

  public parent (parent parent parent)  < / Pre> 

I use the variables back to the original form (in this case either F1 or F2 ) to add data to lists or everything else

Now here's my problem. I'm talking like this for now:

  if (parent.GetType () == typeof (f1)) {((f1) parent) .list.Add ("A"); } And if (Parents getType () == Type (f2)) {((2) parent) .list.Add ("a"); }   

So I am making a check for every parent, how can I do this dynamically? Some such

  (parent.GetType () parent) .list.Add ("a");   

But most of it does not work Has anyone got the solution?

I'm not sure that this is the best solution, but I How to do this:

  Abstract class ParentForm {... public abstract void update  (T updateValue)} public class f1: ParentForm {... private list & lt ; String & gt; List; Public override zero update (string value) {list.Add (value);}} Public F2: ParentForm {.... Private list & lt; int & gt; list; public override zero updates {int} {...}}   

and so on

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#) -