Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting from an int to a bool in C#

Tags:

c#

int vote;

Insertvotes(objectType, objectId , vote, userID); //calling

For this method call, I want to convert vote to a bool. How can I convert it?

Here is the method signature:

 public static bool Insertvotes(int forumObjectType, 
                                int objectId,
                                bool isThumbUp, 
                                int userID) 
{
    // code...
}
like image 395
Nishant Kumar Avatar asked Dec 02 '22 04:12

Nishant Kumar


2 Answers

You can try something like

Insertvotes(objectType, objectId , (vote == 1), userID); //calling

Assuming that 1 is voted up, and 0 is voted down, or something like that.

like image 95
Adriaan Stander Avatar answered Dec 03 '22 17:12

Adriaan Stander


To go from int to boolean

bool isThumbsUp = Convert.ToBoolean(1); //Will give you isThumbsUp == true

To go from boolean to int

int isThumbsUp = Convert.ToInt32(false); //Will give you isThumbsUp == 0
like image 26
Pieter Germishuys Avatar answered Dec 03 '22 16:12

Pieter Germishuys