I am trying to grab a value in a text file (under a line called #Hostname). This used to work when the the hostname was purely an integer (int.TryParse), but now I am using a string (string.TryParse) I am unable to get it because “‘string’ does not contain a definition for ‘TryParse'” Is there anything else I can use?
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);
}
It’s already a string, so you don’t need to parse it at all: