Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
    }
 }
like image 644
Henry Avatar asked Feb 23 '23 22:02

Henry


2 Answers

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]);

like image 111
KV Prajapati Avatar answered Feb 25 '23 13:02

KV Prajapati


It looks like movie_title[] is some sort of array of a numeric type. If it's an array of int, then

Attempt = int.TryParse(vTemp, out movie_title[current_movie]);

should work.

like image 27
Jeremy McGee Avatar answered Feb 25 '23 15:02

Jeremy McGee