我试图在文本文件中获取一个值(在一个名为#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)
| 归档时间: |
|
| 查看次数: |
1067 次 |
| 最近记录: |