2012-10-12 19 views
6

Possible Duplicate:
Help converting type - cannot implicitly convert type ‘string’ to ‘bool’परोक्ष 'bool'

के प्रकार 'int' कनवर्ट नहीं कर सकता मैं बहुत भाषा के लिए नया हूँ n मैं एक अच्छा प्रोग्रामर नहीं हूँ। यह कोड मुझे त्रुटि दे रहा है:

cannot implicitly convert type int to bool.

मुझे यकीन नहीं है कि मैं क्या गलत कर रहा हूं। क्या कुछ मुझे बता सकते हैं कि मैं क्या गलत कर रहा हूं। किसी भी मदद की सराहना की जाएगी किसी भी सिफारिश से भी मदद मिलेगी।

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()) 
        { 
       } 
       } 

      } 


      } 
       } 
+0

विभिन्न प्रकार, लेकिन एक ही विचार। * जहां * त्रुटि है पर ध्यान दें - यह आपको सीधे समस्या पर ले जाएगा। –

+0

जहां आपने सीमा के लिए चर घोषित किया है OfGuess? – Nich

+0

मैंने इसे एक कॉन्स के रूप में घोषित किया। कक्षा घोषणा के ठीक बाद। – user1730332

उत्तर

9

लाइन

if (userInput = mag.randomMagnifier()) 

if (userInput == mag.randomMagnifier()) 
11

सही होना चाहिए इस:

if (userInput = mag.randomMagnifier()) 

रहे हैं:

if (userInput == mag.randomMagnifier()) 

यहां आप if कथन में मान निर्दिष्ट कर रहे हैं, जो गलत है। "==" का उपयोग करने के लिए आपको स्थिति की जांच के लिए, स्थिति को जांचना होगा।
if कथन बूलियन मान देता है, और क्योंकि आप यहां मूल्य आवंटित कर रहे हैं, यह त्रुटि दे रहा है।

3

आप = परिवर्तन के बजाय == उपयोग करना चाहिए: Lif(userinput = mag.randommagnifier()) के लिए

if(userinput == mag.randommagnifier()) 
3

एक अगर बयान हमेशा एक अभिव्यक्ति जो एक बूलियन मान का मूल्यांकन होता है। आपकी लाइन

if (userInput = mag.randomMagnifier()) 

bool नहीं है जो त्रुटि उत्पन्न कर रहा है। आप शायद

if (userInput == mag.randomMagnifier()) 
3

हालत

userInput = mag.randomMagnifier() 

जरूरतों मतलब क्या आप userInput मूल्य असाइन करने की कोशिश कर रहा है और फिर इसे bool करने के लिए पूर्णांक परिवर्तित करने के लिए कोशिश करता है

userInput == mag.randomMagnifier() 

किया जाना है। सी # के साथ यह संभव नहीं है।

संबंधित मुद्दे