Skip to content

Commit

Permalink
add copy and update example for structs
Browse files Browse the repository at this point in the history
  • Loading branch information
sezna committed Aug 22, 2024
1 parent 6b32aef commit 5761b2a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions samples/language/CopyAndUpdateOperator.qs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ function Main() : Unit {
w/ 1 <- 100
w/ 3 <- 200;
Message($"Updated array: {new_array}");

// In addition to arrays, we can also copy-and-update structs.
// First, let's define a struct called `Complex` which represents a
// complex number.
struct Complex { Real : Double, Imaginary : Double }
// Instantiation of the above struct.
let complex = new Complex { Real = 42.0, Imaginary = 0.0 };

// `new_complex` is a new instance of the `Complex` struct with the
// `Real` field updated to `100.0`.
// `complex` is unchanged.
let new_complex = new Complex { ...complex, Real = 100.0 };
}

0 comments on commit 5761b2a

Please sign in to comment.