在C#中分割错误? [IndexOutOfRangeException:数组索引超出范围。]

时间:2019-04-15 09:01:40

标签: c# .net unity3d

我正在尝试读取ConfigFile(txt文件),其中以这种形式包含一些参数:“ showHelp = F1”

static List <string> read(string path)
{
    List<string >lines = File.ReadAllLines(path).ToList();
    if (lines == null)
    { Debug.Log("empty file"); }
    return lines;
}
public static Dictionary<string, string> ReadConfigFile (string path)
{
    List<string> Lines =new List<string>();
    Lines = read(path);
    Dictionary<string, string> content = new Dictionary<string, string>();
    foreach (string line in Lines)
       {
        if (line.Contains('=') == false)
        { continue;}
        string replaced = Regex.Replace(line, @"\p{C}+", string.Empty);
        string[] split = replaced.Split('=');
        content.Add(split[0], split[1]);
    }  

    return (content);
}

错误在于content.add(split [0],split [1])?

0 个答案:

没有答案