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
  • 24,241
  • 10
  • 66
  • 110
foluis
  • 858
  • 2
  • 10
  • 21

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
  • 24,241
  • 10
  • 66
  • 110