-
Notifications
You must be signed in to change notification settings - Fork 130
Q# Structs
Q# structs are a way to organize your code.
Structs can be declared in the same scopes as callables by using the struct
keyword. They have a name and use curly braces to list our named fields.
struct Foo {
First : Int,
Second : Double,
}
To construct a declared struct, use the new
keyword with the struct type name and curly braces to list out the field assignments.
let foo = new Foo { First = 3, Second = 4.5 };
There is also a copy-constructor syntax that is very similar to the regular constructor syntax. When listing field assignments, you first list the existing struct object to copy from preceded by ...
. When copying, you only list out the field assignments you want to change during the copying.
let bar = new Foo { ...foo, Second = 6.5 };
To access the field members of a struct object, the .
operator is used.
let x = bar.First;
Q# Wiki
Overview
Q# language & features
- Q# Structs
- Q# External Dependencies (Libraries)
- Differences from the previous QDK
- V1.3 features
- Curated list of Q# libraries
- Advanced Topics and Configuration
OpenQASM support
VS Code
Python
Circuit diagrams
Azure Quantum
For contributors