且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法隐式转换类型'诠释'到'布尔'

更新时间:2022-10-23 15:33:49

 如果(userInput = mag.randomMagnifier())

 如果(userInput == mag.randomMagnifier())


Possible Duplicate:
Help converting type - cannot implicitly convert type ‘string’ to ‘bool’

I am very new to the language n I am not a good programmer. This code is giving me error:

cannot implicitly convert type int to bool.

I am not sure what I am doing wrong. Can some tell me what I am doing wrong. Any help would be appreciated n any recomendation would also help.

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

   namespace ConsoleApplication2
   {
     class mysteryVal
  {
   public const int limitOfGuess = 5;

  // Data member
    public int mystVal;
         private int numOfGuess ;
      private randomNumberMagnifier mag = new randomNumberMagnifier();

      public int randomMag(int num)
     {
        return num + mystVal;
      }

     // Instance Constructor
     public mysteryVal()
     {
        mystVal = 0;
         numOfGuess = 0;
            }

           public void game(int user)
          {
              int userInput = user;
               if (numOfGuess < limitOfGuess)
                     {
                  numOfGuess++;
                 if (userInput = mag.randomMagnifier())
                   {
                }
               }

           } 


           }
                } 

The line

if (userInput = mag.randomMagnifier())

should be

if (userInput == mag.randomMagnifier())