1
I had an idea to apply in loops and wanted to make a method bool.toogle()
where the variable extends the same value will receive the opposite value. Something like this:
bool variavel = true;
variavel.toogle();
//variavel agora possui o valor false
That is not possible.
bool
is a value type, logo is passed by value and not by reference. Any change within the method is not effected at the original value.– ramaral
I discovered in my tests that this is really impossible in C#, but in VB.NET works using Byref
– Kaizonaro
In C# there is also the possibility to pass value type by reference, declaring these parameters with ref or out, however, in extension methods, it is not allowed to do so in the first parameter, the one that is preceded by
this
.– ramaral