Tuesday, March 27, 2018

How do you convert Integer to Boolean in C#?


Start Interactive C# in Visual Studio Community 2017. Here are examples of integers (+ and -) and 0 converted to Boolean, using the Convert.ToBoolean(). This functions has 8 overloads.

Read here about running C# in interactive mode.

> bool p = Convert.ToBoolean(6);
> p
true
> bool k = Convert.ToBoolean(0);
> k
false
> bool q = Convert.ToBoolean(-8);
> q
true



No comments: