❔ properties/constructor question
Why do we need another variable (model = modelName) ? Why cant we just set it like this
Sorry for such a basic question
/close Model{ get; set; }{ get; }set;=>class Car
{
public string Model { get; set; }
public string Color { get; set; }
public int Year { get; set; }
// Create a class constructor with multiple parameters
public Car(string modelName, string modelColor, int modelYear)
{
Model = modelName.ToUpper();
Color = modelColor.Trim().ToUpper();
Year = modelYear;
} Model = modelName.ToUpper();var car = new Car(..., ..., ...);
car.Color = "red"; // invokes the setterclass Foo
{
private int _bar;
public int GetBar()
{
return _bar;
}
public void SetBar(int bar)
{
_bar = bar;
}
}class Foo
{
private int _bar;
public int GetBar() => _bar;
public void SetBar(int bar) => _bar = bar;
}class Foo
{
private int _bar;
public int Bar {
get { return _bar; }
set { _bar = value; }
}
}class Foo
{
private int _bar;
public int Bar {
get => _bar;
set => _bar = value;
}
}class Foo
{
public int Bar { get; set; }
}