Суть проблемы:
Имеется абстрактный класс А, в нем имеется свойство:
protected abstract bool IsFixedSize
{
get;
}
Другой класс Б наследуется от данного + реализует интерфейс(в котором описанно такое же свойство: bool IsFixedSize{ get; }).
Б:
protected override bool IsFixedSize
{
get { return false; }
}
сильно ругается ругается на protected, компилятор кушает на ура.
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
Здравствуйте, xvost, Вы писали:
X>Здравствуйте, Zihotki, Вы писали:
Z>>сильно ругается ругается на protected, компилятор кушает на ура.
X>Поддерживаю вопрос nikov'а
X>Приведи код целиком
Покурил мсдн, оказалось что методы, реализующие интерфейс должны быть обязательно паблик... Хотя компилер кушает то, что я приводил.
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>
Здравствуйте, xvost, Вы писали:
X>Здравствуйте, Zihotki, Вы писали:
Z>>сильно ругается ругается на protected, компилятор кушает на ура.
X>Поддерживаю вопрос nikov'а
X>Приведи код целиком
Вот код:
interface IMyInterface
{
int GetValue(int id);
string MyProperty { get; set;}
}
class MyClass : IMyInterface
{
private string _myProperty;
#region IMyInterface Members
protected int GetValue(int id)
{
return 666;
}
public string MyProperty
{
get { return _myProperty; }
set { _myProperty = value; }
}
#endregion
}
Посмотрел в стандарте языка, вот что там нашел:
C# provides an alternative way of implementing these methods that allows the implementing class to avoid having these members be public. Interface members can be implemented using a qualified name. For example, the EditBox class could instead be implemented by providing IControl.Paint and IDataBound.Bind methods.
public class EditBox: IControl, IDataBound
{
void IControl.Paint() {…}
void IDataBound.Bind(Binder b) {…}
}
Interface members implemented in this way are called explicit interface members because each member explicitly designates the interface member being implemented. Explicit interface members can only be called via the interface. For example, the EditBox’s implementation of the Paint method can be called only by casting to the IControl interface.
class Test
{
static void Main() {
EditBox editbox = new EditBox();
editbox.Paint(); // error: no such method
IControl control = editbox;
control.Paint(); // calls EditBox’s Paint implementation
}
}
страницы 44-45
... << RSDN@Home 1.1.4 stable SR1 rev. 568>>