I need to convert several Java classes to C#, but I have faced few problems.
In Java I have following class hierarchy:
public abstract class AbstractObject { public String getId() { return id; } } public class ConcreteObject extends AbstractObject { public void setId(String id) { this.id= id; } }
There are implementation of AbstractObject which do not need to have setId() defined, so I cannot move it up in the hierarchy.
How to convert this to C# using properties? Is that possible?
I would suggest using method calls as you’ve already outlined to make sure that the usage of the class is clear to the caller. If you’re set on implementing it using properties, then you could do the following (some documentation for the new keyword can be found here).