I am trying to define a property inside the main class in my Windows Service. The property will be used to retrieve the name of the process whenever required.
For eg:
public string PName
{
return SomeProcess.Name;
}
public string PID
{
return SomeProcess.ProcessId;
}
public Process SomeProcess
{
private Process[] myProcess = Process.GetProcessesByName("notepad"); //Process is underlined here with red wavy line saying "A get or set accessor method is expected"
get
{return myProcess[0];}
}
The problem is inside the SomeProcess property written in the comment. What am I doing wrong here?
Make it like this:
or
EDIT
Note that you need to decide when you want to get the processes. If you do it as I showed in my first sample the process will be retrieved when the class is instantiated. The second way is more robust as it will retrieve the process when you ask for the value of the property.
I stated both answers because you asked what the error means and is more about private and local variables.