Property does not exist in the current context

后端 未结 4 1332
旧时难觅i
旧时难觅i 2021-01-29 00:54

I\'m getting the following error :

\"Property does not exist in the current context\".

I checked on StackOverflow the usual causes

4条回答
  •  旧巷少年郎
    2021-01-29 01:32

    Problem is your lack of basic understanding of OOP. You're trying to assign the base class property from the class scope which is not the way it works in OOP. You have to create some "callable" scope eg. constructor, and inside of that scope assign your parent's fields/properties:

    public class Audi : Voiture {
    // Draper() ...
    
        public Audi() : base() {
            Marque = "Audi";
        }
    }
    

    more descriptive answer :
    Everything inside a class scope is known as definition and every other scope in it is called an implementation. Since you've defined ( made a definition ) of that field/property in your parent class, you have to assign it in an implementation where access modifiers of that field/property allows you to or in the very same moment you're defining this field/property.

提交回复
热议问题