3
$\begingroup$

I'm writing a Q# program and I'm calling an operation defined in the program that outputs a Result (One or Zero).

For example something like this:

output = QuantumOperation.Run(sim).Result;

I want to convert now output to a bool within C#, but I don't know how.

One way to go around this is to change the output of QuantumOperation to be a bool and transforming the result at the end of the operation with ResultAsBool(result). However, I want to maintain the output of the operation to be a Result. So ideally the conversion should happen within the C# host code.

$\endgroup$

1 Answer 1

4
$\begingroup$

Q# type Result is represented by C# class Microsoft.Quantum.Simulation.Core.Result; in particular, it has constants Result.Zero and Result.One that you can compare the return of your operation to.

using Microsoft.Quantum.Simulation.Core;

boolOutput = (QuantumOperation.Run(sim).Result == Result.One);
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.