'string'不包含'TryParse'b的定义

Mik*_*ike -2 .net c# windows

我试图在文本文件中获取一个值(在一个名为#Hostname的行下).当主机名纯粹是一个整数(int.TryParse),这曾经工作,但现在我使用的是一个字符串(string.TryParse)我无法得到它,因为"'string'不包含'TryParse'的定义"我还能用什么吗?

   private void GetGeneralConfig()
    {
        // lets grabs the info from the config!
        var lines = File.ReadAllLines("general_settings.ini");
        var dictionary = lines.Zip(lines.Skip(1), (a, b) => new { Key = a, Value = b })
                              .Where(l => l.Key.StartsWith("#"))
                              .ToDictionary(l => l.Key, l => l.Value);
        // lets define variables and convert the string in the dictionary to int for the sock.connection method!
        string.TryParse(dictionary["#Hostname"], out hostname);

    }
Run Code Online (Sandbox Code Playgroud)

Ry-*_*Ry- 8

它已经是一个字符串,所以你根本不需要解析它:

hostname = dictionary["#Hostname"];
Run Code Online (Sandbox Code Playgroud)