日期:2014-05-18  浏览次数:20927 次

C#里有专门用来读取ini文件的类吗?
如果没有自带
哪位大牛有自己写的,封装好的,足够安全的读取ini的类

------解决方案--------------------
这还不是商业化的代码
C# code

/// INIFile 的摘要说明。
public class INIFile{
public string path;

public INIFile(string INIPath){
    path = INIPath;
    }

[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);

[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,string key,string def, StringBuilder retVal,int size,string filePath);

public void IniWriteValue(string Section,string Key,string Value){
    WritePrivateProfileString(Section,Key,Value,this.path);
    }


public string IniReadValue(string Section,string Key){
    StringBuilder temp = new StringBuilder(255);
    int i = GetPrivateProfileString(Section,Key,"",temp, 255, this.path);
    return temp.ToString();
    }
}

------解决方案--------------------
c#没有,可以利用kernel32.dll里的方法
就像楼上的

或者利用stream自己写一个
------解决方案--------------------
探讨
C#比较倾向于用XML,ini已经是比较过时的配置文件了.

------解决方案--------------------
XML把。。挺好用而且世界通用啊。。。
------解决方案--------------------
XML方便,不用你干什么,写进去读出来都是framework完成的
------解决方案--------------------
xml挺好

要用ini就用1楼写出的api吧