oop - Polymorphism for variables in C# -


is there way implement polymorphism variables in c#?

basically want write this:

public class baseclass { }  public class finalclass : baseclass { }  public class {    public baseclass baseclassproperty {get; set;} }  public class b : {    public override finalclass baseclassproperty {get; set;} } 

i know generics, thnk it's not solution since can end -

 public class a<t,v,c>  {     public t tvalue;     public v vvalue;     public c cvalue;  } 

i know keyword "new" find "cheesy".

edit: i'll explain situation avoid xy problem.

public abstract class basegamemanager {     public baseaccount account; }                           public abstract class baseaccount { }  public class gamemanager : basegamemanager {     public account account; }                           public class account : baseaccount { } 

sometimes, i'll referencing object gamemanager , basegamemanager. when i'll referncing gamemanager don't want cast account property account class every time. that's problem. talking generics being since account not property inherit way described.

i know generics, thnk it's not solution since can end this

well, perfect solution. generics way go if want type classes dynamically.

you class a need 1 generic type parameter, doesn't seem lot me. have core base classes , have quite generic type parameters, , still lot easier work if didn't have that.

proposed code:

public class a<bc> bc : baseclass {    public bc baseclassproperty {get; set;} }  public class b : a<finalclass> { } 

Comments