c# i'm having this error please help me!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cowdung7
    New Member
    • Dec 2008
    • 3

    c# i'm having this error please help me!

    Code:
    public bool searchGame(string gameName)
        {
            string[] searchGame = new string[] { "Tibia", "Combat Arms", "Need for Speed", "Moto GP", "Risk", "Red Alert", "Monopoly", "Scrabble" };
    
            if (gameName.Length > 0)
            {
                for (int i = 0; i <= 7; i++)
    
                    if (searchGame[i] == gameName)
                    {
                        return true;
                    }
            }
            else
            {
                return false;
            }
        }
    // the error stated "Service.search Game(string): not all code paths return a value"

    anyone knows how to solve this?
    Last edited by Banfa; Dec 7 '08, 10:25 AM. Reason: Adde
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Suppose gameName is not an empty string but it is not a valid game name; what does your method return? That's what the compiler is complaining about.

    btw, this is the C and C++ forum. C# is an entirely different language. Questions on C# should be posted in the .NET forum. Oh, and don't double post.

    kind regards,

    Jos (moderator)

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      I think your second 'if' statement needs an 'else' counterpart that returns false. The error says it all: not every possible path returns a value.

      Comment

      Working...