I have a problem with the event understanding. For some reason, I can't subscribe to my event. The visual studio is saying
Error CS0029 Cannot implicitly convert type 'void' to 'FileSystemWatcher.FileSystemWatcher.Handler' FileSystemWatcher C:\Users\Diord\source\repos\FileSystemWatcher\FileSystemWatcher\Program.cs 16 Active
when I do this
fileSystemWatcher.Changed += ShowMessage();
class Program
{
static void Main(string[] args)
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher("C:\\");
//next line is highlighted
fileSystemWatcher.Changed += ShowMessage();
}
public void ShowMessage()
{
Console.WriteLine("Hello Event!");
}
}
class FileSystemWatcher
{
readonly string _path;
private string[] Files { get; set; }
public FileSystemWatcher(string path)
{
_path = path;
}
public delegate void Handler();
public event Handler Changed;
}