Skip to content

Commit

Permalink
Fixed bug 44001. (#44018)
Browse files Browse the repository at this point in the history
Co-authored-by: Adit Sheth <[email protected]>
  • Loading branch information
shethaadit and Adit Sheth authored Dec 19, 2024
1 parent e78758d commit 2d21c75
Showing 1 changed file with 8 additions and 1 deletion.
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];
}

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

0 comments on commit 2d21c75

Please sign in to comment.