Краткий ответ: description
- это специальный тип переменной, называемый " field ". Вы можете прочитать в полях на MSDN .
Длинный ответ: Вы должны получить доступ к защищенному полю в конструкторе, методе, свойстве и т. Д. Подкласса.
class Subclass
{
// These are field declarations. You can't say things like 'this.description = "foobar";' here.
string foo;
// Here is a method. You can access the protected field inside this method.
private void DoSomething()
{
string bar = description;
}
}
Внутри объявления class
вы объявляете членов класса. Это могут быть поля, свойства, методы и т. Д. Это не обязательные операторы для выполнения. В отличие от кода внутри метода, они просто сообщают компилятору, каковы члены класса.
Внутри определенных членов класса, таких как конструкторы, методы и свойства, вы размещаете свой императивный код. Вот пример:
class Foo
{
// Declaring fields. These just define the members of the class.
string foo;
int bar;
// Declaring methods. The method declarations just define the members of the class, and the code inside them is only executed when the method is called.
private void DoSomething()
{
// When you call DoSomething(), this code is executed.
}
}