methods - C# - Convert from bool to bool* -
i need use specific method job done - cannot other method or assembly. method takes following parameters:
void method(bool* ison) {/* code... */}
i try use false the parameter 'ison', visual studio tells "argument 1: cannot convert type 'bool' 'bool*'".
how convert/use bool* act appropriately?
thanks in advance.
edit: not duplicate of usefulness of bool* in c# because asking conversion pointer type , type itself. also, thread mentioned asks uses of bool*, not directly answer question.
you cannot pass false
, because constants not have address.
in order pass pointer false
, make variable, set false
, , use &
operator take variable's address:
unsafe class program { static void foo(bool* b) { *b = true; } static void main(string[] args) { bool x = false; console.writeline(x); // prints false foo(&x); console.writeline(x); // prints true } }
note how method allowed change variable through pointer.
Comments
Post a Comment