delphi - Properties without 'property type' in C# -


i converting delphi code c#.

i have complex classes structure class main 'trunk' of children.

in delphi can define private/protected field type , property field same type, , not write type in child classes anymore.

here bit (and functional) example:

program project1;  {$apptype console}  uses   sysutils;  type   parent = class   strict protected     _myfirstfield: int64;   public     property myfirstfield: int64    write _myfirstfield;   end;    child1 = class(parent)   public     // inherits write/set behaviour..     // , doesn't need define type 'over , over' on child classes.     //     // ******* note myfirstfield here has not type.... ************     property myfirstfield        read _myfirstfield;  // adding read behaviour property.   end;  var   child1instance: child1; begin     child1instance := child1.create;     //child1instance.myfirstfield := 'an string';  <<-- compilation error because type     child1instance.myfirstfield := 11111;     writeln(inttostr(child1instance.myfirstfield));     readln; end. 

as can see don't need define property type on , over. if need change var type in future, can change in parent class.

is there way same behaviour in c#?

no, there ist. types on public api must explicit. time aren't explicit var, limited method variables.

further, can't change signature in c# (adding public getter in subclass) - have re-declare it:

// base type  protected string foo {get;set;}  // derived type new public string foo {     { return base.foo; }     protected set { base.foo = value; } } 

but new suggests: unrelated property , not required have same type.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -