无法隐式转换类型'诠释'到'布尔' [英] Cannot implicitly convert type 'int' to 'bool'

查看:192
本文介绍了无法隐式转换类型'诠释'到'布尔'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:结果
帮助转换类型 - 不能隐式转换类型'字符串'到'布尔'






我很新的语言ñ我不是一个优秀的程序员。此代码是给我的错误:




不能隐式转换int类型为bool




我不知道我做错了。
能有的告诉我,我做错了。 。任何帮助,将不胜感激n中的任意recomendation也将有助于

 使用系统; 
使用System.Collections.Generic;
使用System.Linq的;
使用System.Text;

命名空间ConsoleApplication2
{
类mysteryVal
{
公共const int的limitOfGuess = 5;

//数据成员
公众诠释mystVal;
私人诠释numOfGuess;
私人randomNumberMagnifier MAG =新randomNumberMagnifier();

公众诠释randomMag(INT NUM)
{
返回NUM + mystVal;
}

//实例构造
公共mysteryVal()
{
mystVal = 0;
numOfGuess = 0;
}

公共无效游戏(INT用户)
{
INT userInput =用户;
如果(numOfGuess< limitOfGuess)
{
numOfGuess ++;
如果(userInput = mag.randomMagnifier())
{
}
}

}


}
}


解决方案

 如果(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())

这篇关于无法隐式转换类型'诠释'到'布尔'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆