c#读写INI

  
    
// 读写INI
public class GF_INI
{
[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);
[DllImport(
" kernel32.dll " )]
public static extern int Beep( int dwFreq, int dwDuration);

// 读ini
public static void iniFile_SetVal( string in_filename, string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, in_filename);
}

// 写INI
public static string iniFile_GetVal( string in_filename, string Section, string Key)
{
StringBuilder temp
= new StringBuilder( 255 );
int i = GetPrivateProfileString(Section, Key, "" , temp, 255 , in_filename);
if (i == 0 )
return "" ;
else
return temp.ToString();
}
}

你可能感兴趣的:(ini)