What are the differences between the two and when would you use an \"object initializer\" over a \"constructor\" and vice-versa? I\'m working with C#, if that matters. Als
If you have properties that MUST be set on your object for it to work properly, one way is to expose just a single constructor which requires those mandatory properties as parameters.
In that case, you cannot create your object without specifying those mandatory properties. Something like that cannot be enforced by object initializers.
Object initializers are really just a "syntax convenience" to shorten initial assignments. Nice, but not really very functionally relevant.
Marc