error CS0029:Cannot implicitly convert type 'int' to 'bool'

while ((System.Convert.ToInt32(strupcolid)!=0));

where is the problem




Answer this question

error CS0029:Cannot implicitly convert type 'int' to 'bool'

  • Drew Marsh

    What type is strupcolid Are you sure that's the line that's causing your problem That particular line of code should compile just fine assuming strupcolid is a string.

    Regards,

    Donavan Hoepcke


  • FandangoAmeruso

    Dear all,

    thank you very much for your advice.

    I am very sorry to say that due to carelessness or other reasons, I mistakingly regard this line as error line.

    Actually the error line is:

    for (int j=arrcolid.Length-1;j=0;j--) //<--error line
    {
    path += "<a href=article/" + arrcolid[j] + ".htm>" + arrcolname[j] + "</a>>>";
    }



  • AndrewBadera

    I don't know what you are doing wrong, but the following code does NOT generate the error for me:

    static void Main(string[] args)
    {
    string
    strupcolid = "0";
    while
    ((System.Convert.ToInt32(strupcolid)!=0))
    ;
    }



  • anydobbo

    James, thks!

    = and ==, haha, I am too careless to mind the difference.

    thks again!



  • Luke Breuer

    >> for (int j=arrcolid.Length-1;j=0;j--)

    Well, that's easy.

    j=0 is an assignment, which evaluates to 0 (int)

    j==0 is a comparison, which evaluate to t/f (bool)



  • Jim Stockwell

    while ((System.Convert.ToInt32(strupcolid)!=0));

    Why does this line end in a semicolon, is this watching something in another thread If so, there are much better ways to do that.

    As someone said, this line cannot cause that error, not as it's posted here. != will return a bool. You could try breaking it up into more than one line, and see where the problem is then.



  • error CS0029:Cannot implicitly convert type 'int' to 'bool'