In swift, it is possible to toggle a Boolean by simply calling .toggle() on the var.
var isVisible = false
isVisible.toggle() // true
I wanted to create the same functionality in C#, so I wrote an extension method on 'bool'
public static class Utilities {
public static void Toggle(this bool variable) {
variable = !variable;
//bool temp = variable;
//variable = !temp;
}
}
However, it does not work, and I suspect that it has to do with bool in C# being value types, where as they are reference types in swift.
Is there a way to implement the same toggle function in C#?