I am writing a component for grasshopper in c#. But went i pass a number through a boolean it give me a a false or a true value. How can i add a exception to this event. I only want to pass as parameter booleans types
How can i avoid cast numbers to booleans in C#?
116 views Asked by Starsky Lara At
2
There are 2 answers
1
On
Wihtout any code is hard to tell, but if your method must have int
in its signature, you can "translate" to result = value != 0
.
But why don't you just modify your signature to bool
anyway?
If you want to, you may have both!
void method(int value) {
bool result = value != 0;
method(result);
}
void method(bool value) {
// your code
}
Boolean types in C# can only have
true
orfalse
values. If you wish to pass a number as a parameter, define it asint
.