0

Difference in instantiating a variable using parentencis and not

with parentheses

var myCity = new CityDto()
{
   Id = 1,
   Name = "NY"
};

Without parentheses

var myCity = new CityDto
{
   Id = 1,
   Name = "NY"
};
Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
foluis
  • 988
  • 2
  • 10
  • 23

1 Answers1

2

There's no difference. When calling the default constructor, but using the object initializer syntax, the () can be removed.

If you were to remove the object initializer, the () are required.

Jonesopolis
  • 25,034
  • 12
  • 68
  • 112