读书人

哪位高手能帮小弟我解释下这个代码是如

发布时间: 2012-01-15 22:57:49 作者: rapoo

谁能帮我解释下这个代码是怎么搞到值的?
string DBServer = BCPCommon.ReadINI( "DB ", "DBServer ", " ", INIPath + "\\BCP.ini ");//调用ReadINI方法

/*ReadINI方法*/
public static string ReadINI(string section, string key, string def, string filename)
{
StringBuilder temp = new StringBuilder(1024);

try
{
GetPrivateProfileString(section, key, def, temp, 1024, filename);//调用GetPrivateProfileString方法
return temp.ToString();
}
catch (Exception ex)
{
throw ex;
}
finally
{
temp = null;
}
}


/*GetPrivateProfileString方法*/
[DllImport( "kernel32 ")]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName
);


/*.ini文件*/
[DB]
DBServer=203.163.38.158
DBName=Northwind
UserID=sa
Password=sa

[Path]
BCPOutPath=c:\BCPDemo
BCPInPath=c:\BCPDemo
LogPath=c:\BCPDemo

[Flag]
Run=O

[Timer]
Interval=100


[解决办法]
ini只有一种格式...

[section]
key=value
....

你应该去看看相关的文档...不过也没什么必要了...除了兼容旧的系统ini已经没有应用的价值...

读书人网 >C#

热点推荐