Property does not exist in the current context

后端 未结 4 1326
旧时难觅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:28

    In C#, you can not initialize property in class body. You should initialize them in constructor:

    namespace ConsoleApplication5
    {
        public class Audi : Voiture
        {
            Audi() {
                this.Marque = "Audi";
            }
    
            public void Deraper()
            {
                Console.WriteLine("Vroooouum !!");
            }
        }
    }
    

提交回复
热议问题