Can the get of a property be abstract and the set be virtual?

Posted by K. Georgiev on Stack Overflow See other posts from Stack Overflow or by K. Georgiev
Published on 2010-06-06T19:11:24Z Indexed on 2010/06/06 19:22 UTC
Read the original article Hit count: 283

Filed under:
|
|
|

I have a base class like this:


public class Trajectory{
   public int Count { get; set; }
   public double Initial { get; set { Count = 1; } }
   public double Current { get; set { Count ++ ; } }
}

So, I have code in the base class, which makes the set-s virtual, but the get-s must stay abstract. So I need something like this:


...
   public double Initial { abstract get; virtual set { Count = 1; } }
...

But this code gives an error. The whole point is to implement the counter functionality in the base class instead in all the derived classes. So, how can I make the get and set of a property with different modifiers?

© Stack Overflow or respective owner

Related posts about c#

Related posts about properties