I have a question, because I am a coder of c++, now I need read some c# code. This is a class in a namespace, what I do not understand is the last member;
public string FilePath
{
get { return this.filePath; }
set { this.filePath = value; }
}
I do not know it is a member variable or a member function.
If see it as a member function, it should like
public string FilePath(***)
{
****;
}
but here it doesn’t have a () similar parameter, what type of function is it?
class INIFileOperation
{
private string filePath;
[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 string ReadAppPath()
{
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
return appPath + "\\Setting.ini";
}
public INIFileOperation()
{
this.filePath = ReadAppPath();
}
public void Write(string section, string key, string value)
{
WritePrivateProfileString(section, key, value.ToUpper(), this.filePath);
}
public string Read(string section, string key)
{
StringBuilder SB = new StringBuilder(255);
int i = GetPrivateProfileString(section, key, "", SB, 255, this.filePath);
return SB.ToString();
}
public string FilePath
{
get { return this.filePath; }
set { this.filePath = value; }
}
}
You can view
as a kind of writing
but it gives you the so called
propertyFilePath which can be used asobj.FilePath="abc"orstring abc = obj.FilePath.