I have a C # 2.0 application where the base interface allows read-only access to a value in a particular class. But in a particular class, I would like to have read and write access to this value. So, I have an implementation like this:
public abstract class Base
{
public abstract DateTime StartTime { get; }
}
public class Foo : Base
{
DateTime start_time_;
public override DateTime StartTime
{
get { return start_time_; }
internal set { start_time_ = value; }
}
}
But this gives me an error:
Foo.cs(200,22): error CS0546: 'Foo.StartTime.set': cannot override because 'Base.StartTime' does not have an overridable set accessor
I do not want the base class to have write access. But I want a specific class to provide read / write access. Is there any way to make this work?
Thanks PaulH
Unfortunately, Baseit cannot be changed to an interface, since it also contains non-abstract functionality. Something I had to think about in order to provide an initial description of the problem.
public abstract class Base
{
public abstract DateTime StartTime { get; }
public void Buzz()
{
}
}
My solution is to do this:
public class Foo : Base
{
DateTime start_time_;
public override DateTime StartTime
{
get { return start_time_; }
}
internal void SetStartTime
{
start_time_ = value;
}
}
, , .