I found have found such a line:
var myObject = new MyClass { 42 };
And I would like to know if it is possible to perform such operation. Documentation says that ,,You must use an object initializer if you're defining an anonymous type" so this is obvious but I cant find anything about alone integer in braces.
No, but you can either call a constructor;
new MyClass(42)
if one is defined, or set any settable properties like this;
new MyClass { MeaningOfLife=42 };
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