Result is Q#’s domain-specific type for quantum measurement outcomes. Its only values are Zero and One, corresponding to measurement results 0 and 1. section 4.1.3
Use Result values as measurement data rather than ordinary numeric or Boolean values:
- Measure computational-basis qubits with MResetZ, which returns a Result and resets each qubit to ket-zero. section 4.1.3
- Print or otherwise process results as classical information, but convert explicitly before using numeric or Boolean operations. section 4.1.3
- Store multiple outcomes in Result[] arrays; mutable accumulation supports collecting results during execution. section 4.1.3
Read and validate measurement results
A Q# operation can measure every qubit with MResetZ and return Result[]. A validation routine converts Zero and One values into an integer, compares it with the prepared basis state, and repeats randomized cases. section 4.1.3
Listing 4.3 Q# code to measure all qubits and return the results
operation ReadInformation(qs : Qubit[]) : Result[] {
mutable res = []; #1
for q in qs {
set res += [MResetZ(q)]; #2
}
return res;
}
Inspect the Q# ReadInformation operation that accumulates MResetZ outcomes and returns them as a Result array. section 4.1.3
