Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/csharp/whats-new/csharp-13.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ You can read the details of the changes in the [proposal specification](~/_cshar
The implicit "from the end" index operator, `^`, is now allowed in an object initializer expression. For example, you can now initialize an array in an object initializer as shown in the following code:

```csharp
public class TimerRemaining
{
public int[] buffer { get; set; } = new int[10];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the setter could be left out which would emphase the buffer = below isn't doing a set.

}

var countdown = new TimerRemaining()
{
buffer =
Expand All @@ -94,7 +99,9 @@ var countdown = new TimerRemaining()
};
```

The preceding example creates an array that counts down from 9 to 0. In versions before C# 13, the `^` operator can't be used in an object initializer. You need to index the elements from the front.
The `TimerRemaining` class includes a `buffer` array initialized to a length of 10. The preceding example assigns values to this array using the "from the end" index operator (`^`), effectively creating an array that counts down from 9 to 0.

In versions before C# 13, the `^` operator can't be used in an object initializer. You need to index the elements from the front.

## `ref` and `unsafe` in iterators and `async` methods

Expand Down
Loading