From 303a2240666f17c9a2a6a3024866f28daf22497d Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Wed, 19 Jan 2022 15:34:42 +0000 Subject: [PATCH] Clarify that object initializer can have multiple indexer targets Fixes #411. --- standard/expressions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/standard/expressions.md b/standard/expressions.md index 71dc1853a..08fa3afe7 100644 --- a/standard/expressions.md +++ b/standard/expressions.md @@ -2013,6 +2013,8 @@ initializer_value An object initializer consists of a sequence of member initializers, enclosed by `{` and `}` tokens and separated by commas. Each *member_initializer* shall designate a target for the initialization. An *identifier* shall name an accessible field or property of the object being initialized, whereas an *argument_list* enclosed in square brackets shall specify arguments for an accessible indexer on the object being initialized. It is an error for an object initializer to include more than one member initializer for the same field or property. +> *Note*: While an object initializer is not permitted to set the same field or property more than once, there are no such restrictions for indexers. An object initializer may contain multiple initializer targets referring to indexers, and may even use the same indexer arguments multiple times. *end note* + Each *initializer_target* is followed by an equals sign and either an expression, an object initializer or a collection initializer. It is not possible for expressions within the object initializer to refer to the newly created object it is initializing. A member initializer that specifies an expression after the equals sign is processed in the same way as an assignment ([ยง12.18.2](expressions.md#12182-simple-assignment)) to the target.