Re[2]: Property implementation error
От: Zihotki  
Дата: 30.01.07 11:02
Оценка:
Здравствуйте, 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>>
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.