首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

哪位高手能帮小弟我解释下这个代码是如何搞到值的

2012-01-15 
谁能帮我解释下这个代码是怎么搞到值的?stringDBServerBCPCommon.ReadINI( DB ,DBServer , ,INIPat

谁能帮我解释下这个代码是怎么搞到值的?
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已经没有应用的价值...

热点排行