& # 39;字符串# 39;不包含'TryParse'的定义

本文关键字:定义 TryParse 字符串 包含 | 更新日期: 2023-09-27 18:09:16

在解决这个问题时遇到了一点麻烦,我想在数组中按顺序存储多达50部电影,并允许用户删除/搜索它们。

然而,它给我错误说,parseAttempt不存在,'string'不包含'TryParse'的定义…

这是我到目前为止得到的所有东西,如果它能使事情更清楚。- 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;
    }
 }

& # 39;字符串# 39;不包含'TryParse'的定义

TryParse不是System.String类的成员。基本上TryParseParse方法用于将"字符串"数据值解析为基本类型- int, float等。

删除Attempt = string.TryParse(vTemp, out movie_title[current_movie]);

看起来movie_title[]是某种数字类型的数组。如果是int数组,则

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