.net 操作c#的类
[ 2005-06-03 00:08:53 | 作者: admin ]
注意要将命名空间设为你项目的名称
如将下文中"namespace fund"中的fund改为你的空间名称
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace fund
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class ClassIniFile
{
private string fileName;
[DllImport("kernel32")]
private static extern int GetPrivateProfileInt(
string lpAppName,
string lpKeyName,
int nDefault,
string lpFileName
);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName
);
[DllImport("kernel32")]
private static extern bool WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFileName
);
public ClassIniFile(string filename)
{
fileName=filename;
}
public int GetInt(string section,string key,int def)
{
return GetPrivateProfileInt(section,key,def,fileName);
}
public string GetString(string section,string key,string def)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(section,key,def,temp,1024,fileName);
return temp.ToString();
}
public void WriteInt(string section,string key,int iVal)
{
WritePrivateProfileString(section,key,iVal.ToString(),fileName);
}
public void WriteString(string section,string key,string strVal)
{
WritePrivateProfileString(section,key,strVal,fileName);
}
public void DelKey(string section,string key)
{
WritePrivateProfileString(section,key,null,fileName);
}
public void DelSection(string section)
{
WritePrivateProfileString(section,null,null,fileName);
}
}
}
如将下文中"namespace fund"中的fund改为你的空间名称
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace fund
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class ClassIniFile
{
private string fileName;
[DllImport("kernel32")]
private static extern int GetPrivateProfileInt(
string lpAppName,
string lpKeyName,
int nDefault,
string lpFileName
);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName
);
[DllImport("kernel32")]
private static extern bool WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFileName
);
public ClassIniFile(string filename)
{
fileName=filename;
}
public int GetInt(string section,string key,int def)
{
return GetPrivateProfileInt(section,key,def,fileName);
}
public string GetString(string section,string key,string def)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(section,key,def,temp,1024,fileName);
return temp.ToString();
}
public void WriteInt(string section,string key,int iVal)
{
WritePrivateProfileString(section,key,iVal.ToString(),fileName);
}
public void WriteString(string section,string key,string strVal)
{
WritePrivateProfileString(section,key,strVal,fileName);
}
public void DelKey(string section,string key)
{
WritePrivateProfileString(section,key,null,fileName);
}
public void DelSection(string section)
{
WritePrivateProfileString(section,null,null,fileName);
}
}
}
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=96
这篇日志没有评论。
此日志不可发表评论。