csharp int to bool

Code Example - csharp int to bool

                
                        // Simple way, may crash if intValue > 1
int intValue = 1;
bool boolValue = intValue != 0;
// value of boolValue: true

// Better way
int intValue = 1;
bool boolValue = System.Convert.ToBoolean(intValue);
// value of boolValue: true
                    
                
 

int to bool csharp

                        
                                int i = 0;
bool b = Convert.ToBoolean(i);
                            
                        
 

Related code examples