Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i declare a value that will change with target value

How can i declare a value that will change with target value. like;

bool isInFrozen = true;
bool frozen = isInFrozen;
    
print(frozen); // Prints True

isInFrozen = false; // Value changed

// Im wanting to print isInFrozen's changed value
print(frozen); // But still prints true

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

frozen needs to be a reference

bool isInFrozen = true;
ref bool frozen = ref isInFrozen;

Console.WriteLine(frozen); // Prints True

isInFrozen = false; // Value changed

Console.WriteLine(frozen); // Now prints False

For more details on c# references, take a look at the docs

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading