What would be the best way to implement the following?
I have a collection of objects that implement an interface, internally I want to be able to expose set and get on the properties and externally only get.
Here’s an example of the sort of thing I want… That does’t compile.
public interface ITable { string Name { get; } } internal interface IInternalTable { string Name { get; set; } } internal class Table : ITable, IInternalTable { public string Name { get; set; } public string ITable.Name { get { return Name; } } } public class Database { private List<IInternalTable> tables; public List<ITable> { get { return this.tables; } } }
Use this:
Note: The accessibility modifier used on a get or set accessor can only restrict visibility not increase it.