Skip to content

Literal Notation

Mario Gutierrez edited this page Jan 7, 2017 · 1 revision

You can use object-literal notation in constructing an object.

Card c = new Card { Rank = '5', Suit = 'D' };
Card c = new Card() { Rank = '5', Suit = 'D' }; // Equivalent to above.
Card c = new Card(suit: 'D') { Rank = '5' }; // You can get crazy with this.

The names in the brackets are public fields of the Card class, not the names of the parameters in the constructor.

Clone this wiki locally