Valerie Meunier

Valerie Meunier

  • 958
  • 693
  • 72.1k

error with instantiation in constructor

Jan 2 2023 1:12 PM

Hi

i'm still experiment with instantiation and tried this: i moved the instantiation from Main into the constructor (as recommended by Sachin Singh in a previous post). But i get the error "the name 'auto' doesn't exist".

Thanks. 

V.

using System;
class Car
{
    string model;

    public Car() 
    {
        Car auto = new Car();
    }

    static void Main(string[] args)
    {
        new Car();
        auto.model = "Mustang";
        Console.WriteLine(auto.model);
    }
}
 


Answers (8)