在C#中从int转换为bool

Nis*_*mar 4 c#

int vote;

Insertvotes(objectType, objectId , vote, userID); //calling
Run Code Online (Sandbox Code Playgroud)

对于这个方法调用,我想转换votebool.我怎么转换它?

这是方法签名:

 public static bool Insertvotes(int forumObjectType, 
                                int objectId,
                                bool isThumbUp, 
                                int userID) 
{
    // code...
}
Run Code Online (Sandbox Code Playgroud)

Adr*_*der 8

你可以尝试类似的东西

Insertvotes(objectType, objectId , (vote == 1), userID); //calling
Run Code Online (Sandbox Code Playgroud)

假设1被投票,0被投票,或类似的东西.


Pie*_*uys 5

从 int 到 boolean

bool isThumbsUp = Convert.ToBoolean(1); //Will give you isThumbsUp == true
Run Code Online (Sandbox Code Playgroud)

从 boolean 到 int

int isThumbsUp = Convert.ToInt32(false); //Will give you isThumbsUp == 0
Run Code Online (Sandbox Code Playgroud)