I am trying to do something like:
Object [] x = new Object[2]; x[0]=new Object(){firstName="john";lastName="walter"}; x[1]=new Object(){brand="BMW"};
I want to know if there is a way to achieve that inline declaration in C#
We can create an object without creating a class in PHP, typecasting a type into an object using the object data type. We can typecast an array into a stdClass object. The object keyword is wrapped around with parenthesis right before the array typecasts the array into the object.
The new inline variable declaration syntax allows you to declare the variable directly in a code block (allowing also multiple symbols as usual): procedure Test; begin var I: Integer; I := 22; ShowMessage (I. ToString); end; procedure Test2; begin var I, K: Integer; I := 22; K := I + 10; ShowMessage (K.
yes, there is:
object[] x = new object[2]; x[0] = new { firstName = "john", lastName = "walter" }; x[1] = new { brand = "BMW" };
you were practically there, just the declaration of the anonymous types was a little off.
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