'string' does not contain a definition for 'TryParse'

Henry picture Henry · Sep 21, 2011 · Viewed 23.9k times · Source

Having a little trouble working this one out, I'm wanting to store up to 50 movies in an array in order and allow them to be deleted/searched by users.

However it's giving me errors saying that the parseAttempt does not exist and 'string' does not contain a definition for 'TryParse'...

Here's everything that I've got so far, if it'll help makes things clearer. - http://pastebin.com/V4aAAPf5

// Movie Title
parseAttempt = false;
while (parseAttempt == false)
{
    Console.Write("Enter the movie title >");
    vTemp = Console.ReadLine();
    Attempt = string.TryParse(vTemp, out movie_title[current_movie]);                    
    // Check data valid
    // Check constraints
    if (movie_title[current_movie] <= 0)
    {
        Console.Write("Movie title must be > 0");
        parseAttempt = false;
    }
 }

Answer

kv-prajapati picture kv-prajapati · Sep 21, 2011

TryParse is not a member of System.String class. Basically TryParse or Parse methods are used to parse "string" datavalue into primitive types - int, float etc.

Remove this Attempt = string.TryParse(vTemp, out movie_title[current_movie]);