How do I pass a variable to an event in C#?
.net, c#
Solution
The simplest approach is to use a lambda expression:
watcher.Changed += (sender, args) => HandleWatcherChanged(count);
It sounds like you may want to pass `count` by reference though, if the method wants to update the value.
Problem
I am using FileSystemWatcher On the Changed Event, I want to pass an integer variable. e.g. ``` int count = someValue; FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = "C:\temp"; watcher.Changed += new FileSystemEventHandler(fileSystemWatcher_Changed); ``` on the fileSystemWatcher_Changed, I want to take the count value and then do some work. But how do I get that value. if I make count a global variable, it wouldn't be valid because count changes with each file changed event and it is passed from user.