I have a class Field of which there are two sub-classes AccountField and DecimalField.
ie
class Field{//some properties}
class DecimalField : Field {...}
class AccountField : Field {...}
I then have another class Data which has a member property of type Field.
But it has problems. If I assign a DecimalField variable to the Field property within Data then I cannot use some properties of DecimalFields and also same for Accountfield variables…
What must I do? Which pattern I must use?
I am using C# 4.0 and MS Studio 2010
Yes you can.
Let’s say that you have your field class like this
and the decimal field class like this
,and the Accountfield like this
, and suppose you have a method called DoSomething, which expects a parameter of Field type like the one below
Then to get the concrete type passed in, you can do something like