I define objects from class in C# this way
var something = new SomeThing()
{
Property = "SomeProperty"
}
and this way
var something = new SomeThing
{
Property = "SomeProperty"
}
what is the difference between these definitions?
Nothing. The ()
is redundant. The only thing required is that the object has a default constructor.
Nothing, when the parentheses are empty.
They only make sense when you provide a parameter; you can do that at the same time:
var something = new SomeThing("some other value")
{
Property = "SomeProperty"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With