Ini文件的内容 EXAM:
[ErrorMessage]
Sheep_Theme=1
Time=0
MSG00001E=fsdjkhfsdhfsdnf
1=1
2=2
3=3
4=4之前的做法是:
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        public string ReadIniValue(string Section,string Key,string FilePath)
        {
            StringBuilder sb = new StringBuilder();
            sb.Capacity = 100;
            int i = GetPrivateProfileString(Section, Key, "", sb, 255, FilePath);
            return sb.ToString();
        }
现在打算一次性把Ini文件中的内容都读出来存到一个HashTable中,HashTable中的Key等于Ini文件中的Key
应该怎么实现呢???

解决方案 »

  1.   


    string file = "e:\\1.ini";
    using (StreamReader sr = new StreamReader(file))
    {
        string temp = sr.ReadToEnd();    
        string[] split = temp.Split('\n');
        for (int i = 1; i < split.Length; i++)
        {
            string[] keyvalue = split[i].Split('=');
            Console.WriteLine(String.Format("Key:{0} Value:{1}", keyvalue[0], keyvalue[1]));//这里可以加入Hashtable
        }
    }
      

  2.   

    难道问题没说明白吗??
    简单点就是  之前实现的是每次只读出一行,现在要全部读取然后存到HashTable中
      

  3.   

    这个外部函数的作用,懒得去查了。需要这样去读吗?直接StreamReader好了。读到一个字符串之后再分解.再要不你写到App.config文件里。比在INI文件里也方便多了。