0

What is the difference between initializing an object in these two ways:

MyObject myObject = new MyObject()
{
    Id = 1,
    Color = green
}

VS.

MyObject myObject = new MyObject
{
    Id = 1,
    Color = green
}
user3689167
  • 823
  • 1
  • 12
  • 26

2 Answers2

0

There is no difference, they compile to the same code.

Scott Chamberlain
  • 121,188
  • 31
  • 271
  • 414
-1

There's no difference - the parentheses in the first example are optional. Hope that helps.